Exemple #1
0
 @Override
 public void inject(DimletKey key, DimensionInformation dimensionInformation) {
   SkyDescriptor.Builder builder = new SkyDescriptor.Builder();
   builder.combine(dimensionInformation.getSkyDescriptor());
   SkyDescriptor newDescriptor = DimletObjectMapping.idToSkyDescriptor.get(key);
   if (newDescriptor.specifiesFogColor()) {
     builder.resetFogColor();
   }
   if (newDescriptor.specifiesSkyColor()) {
     builder.resetSkyColor();
   }
   builder.combine(newDescriptor);
   dimensionInformation.setSkyDescriptor(builder.build());
 }
  private void calculateCelestialBodyDescriptors() {
    List<CelestialBodyType> celestialBodies = skyDescriptor.getCelestialBodies();
    // Find the most suitable sun and moon. This is typically the largest sun in the list of
    // celestial bodies.
    int sunidx = -1;
    int bestsun = 0;
    int moonidx = -1;
    int bestmoon = 0;
    for (int i = 0; i < celestialBodies.size(); i++) {
      CelestialBodyType type = celestialBodies.get(i);
      if (type.getGoodSunFactor() > bestsun) {
        bestsun = type.getGoodSunFactor();
        sunidx = i;
      }
      if (type.getGoodMoonFactor() > bestmoon) {
        bestmoon = type.getGoodMoonFactor();
        moonidx = i;
      }
    }

    // Always the same random series.
    Random random = new Random(123);
    random.nextFloat();
    celestialBodyDescriptors = new ArrayList<CelestialBodyDescriptor>();
    for (int i = 0; i < celestialBodies.size(); i++) {
      CelestialBodyType type = celestialBodies.get(i);
      celestialBodyDescriptors.add(new CelestialBodyDescriptor(type, i == sunidx || i == moonidx));
    }
  }
  public void dump(EntityPlayer player) {
    String digits = getDigitString();
    if (!digits.isEmpty()) {
      logDebug(player, "    Digits: " + digits);
    }
    if (forcedDimensionSeed != 0) {
      logDebug(player, "    Forced seed: " + forcedDimensionSeed);
    }
    if (baseSeed != 0) {
      logDebug(player, "    Base seed: " + baseSeed);
    }
    logDebug(player, "    World version: " + worldVersion);
    TerrainType terrainType = getTerrainType();
    logDebug(player, "    Terrain: " + terrainType.toString());
    logDebug(
        player,
        "        Base block: "
            + new ItemStack(baseBlockForTerrain.getBlock(), 1, baseBlockForTerrain.getMeta())
                .getDisplayName());
    if (featureTypes.contains(FeatureType.FEATURE_TENDRILS)) {
      logDebug(
          player,
          "        Tendril block: "
              + new ItemStack(tendrilBlock.getBlock(), 1, tendrilBlock.getMeta()).getDisplayName());
    }
    if (featureTypes.contains(FeatureType.FEATURE_PYRAMIDS)) {
      for (BlockMeta block : pyramidBlocks) {
        if (block != null) {
          logDebug(
              player,
              "        Pyramid blocks: "
                  + new ItemStack(block.getBlock(), 1, block.getMeta()).getDisplayName());
        }
      }
    }
    if (featureTypes.contains(FeatureType.FEATURE_ORBS)) {
      for (BlockMeta block : sphereBlocks) {
        if (block != null) {
          logDebug(
              player,
              "        Orb blocks: "
                  + new ItemStack(block.getBlock(), 1, block.getMeta()).getDisplayName());
        }
      }
    }
    if (featureTypes.contains(FeatureType.FEATURE_HUGEORBS)) {
      for (BlockMeta block : hugeSphereBlocks) {
        if (block != null) {
          logDebug(
              player,
              "        Huge Orb blocks: "
                  + new ItemStack(block.getBlock(), 1, block.getMeta()).getDisplayName());
        }
      }
    }
    if (featureTypes.contains(FeatureType.FEATURE_LIQUIDORBS)) {
      for (BlockMeta block : liquidSphereBlocks) {
        if (block != null) {
          logDebug(
              player,
              "        Liquid Orb blocks: "
                  + new ItemStack(block.getBlock(), 1, block.getMeta()).getDisplayName());
        }
      }
    }
    if (featureTypes.contains(FeatureType.FEATURE_HUGELIQUIDORBS)) {
      for (BlockMeta block : hugeLiquidSphereBlocks) {
        if (block != null) {
          logDebug(
              player,
              "        Huge Liquid Orb blocks: "
                  + new ItemStack(block.getBlock(), 1, block.getMeta()).getDisplayName());
        }
      }
    }
    if (featureTypes.contains(FeatureType.FEATURE_CANYONS)) {
      logDebug(
          player,
          "        Canyon block: "
              + new ItemStack(canyonBlock.getBlock(), 1, canyonBlock.getMeta()).getDisplayName());
    }
    logDebug(player, "        Base fluid: " + new ItemStack(fluidForTerrain).getDisplayName());
    logDebug(
        player,
        "    Biome controller: " + (controllerType == null ? "<null>" : controllerType.name()));
    for (BiomeGenBase biome : getBiomes()) {
      if (biome != null) {
        logDebug(player, "    Biome: " + biome.biomeName);
      }
    }
    for (FeatureType featureType : getFeatureTypes()) {
      logDebug(player, "    Feature: " + featureType.toString());
    }
    for (BlockMeta block : extraOregen) {
      if (block != null) {
        logDebug(
            player,
            "        Extra ore: "
                + new ItemStack(block.getBlock(), 1, block.getMeta()).getDisplayName());
      }
    }
    for (Block block : fluidsForLakes) {
      logDebug(player, "        Lake fluid: " + new ItemStack(block).getDisplayName());
    }
    if (featureTypes.contains(FeatureType.FEATURE_LIQUIDORBS)) {
      for (Block fluid : liquidSphereFluids) {
        logDebug(player, "        Liquid orb fluids: " + new ItemStack(fluid).getDisplayName());
      }
    }
    if (featureTypes.contains(FeatureType.FEATURE_HUGELIQUIDORBS)) {
      for (Block fluid : hugeLiquidSphereFluids) {
        logDebug(
            player, "        Huge Liquid orb fluids: " + new ItemStack(fluid).getDisplayName());
      }
    }
    for (StructureType structureType : getStructureTypes()) {
      logDebug(player, "    Structure: " + structureType.toString());
    }
    if (structureTypes.contains(StructureType.STRUCTURE_RECURRENTCOMPLEX)) {
      for (String type : dimensionTypes) {
        logDebug(player, "    RR DimensionType: " + type);
      }
    }
    for (EffectType effectType : getEffectTypes()) {
      logDebug(player, "    Effect: " + effectType.toString());
    }
    logDebug(player, "    Sun brightness: " + skyDescriptor.getSunBrightnessFactor());
    logDebug(player, "    Star brightness: " + skyDescriptor.getStarBrightnessFactor());
    float r = skyDescriptor.getSkyColorFactorR();
    float g = skyDescriptor.getSkyColorFactorG();
    float b = skyDescriptor.getSkyColorFactorB();
    logDebug(player, "    Sky color: " + r + ", " + g + ", " + b);
    r = skyDescriptor.getFogColorFactorR();
    g = skyDescriptor.getFogColorFactorG();
    b = skyDescriptor.getFogColorFactorB();
    logDebug(player, "    Fog color: " + r + ", " + g + ", " + b);
    SkyType skyType = skyDescriptor.getSkyType();
    if (skyType != SkyType.SKY_NORMAL) {
      logDebug(player, "    Sky type: " + skyType.toString());
    }
    for (CelestialBodyType bodyType : skyDescriptor.getCelestialBodies()) {
      logDebug(player, "    Sky body: " + bodyType.name());
    }

    if (weatherDescriptor.getRainStrength() > -0.5f) {
      logDebug(player, "    Weather rain: " + weatherDescriptor.getRainStrength());
    }
    if (weatherDescriptor.getThunderStrength() > -0.5f) {
      logDebug(player, "    Weather thunder " + weatherDescriptor.getThunderStrength());
    }

    for (MobDescriptor mob : extraMobs) {
      if (mob != null) {
        if (mob.getEntityClass() == null) {
          logDebug(player, "    Mob: " + mob);
        } else {
          logDebug(player, "    Mob: " + mob.getEntityClass().getName());
        }
      }
    }
    if (peaceful) {
      logDebug(player, "    Peaceful mode");
    }
    if (noanimals) {
      logDebug(player, "    No animals mode");
    }
    if (shelter) {
      logDebug(player, "    Safe shelter");
    }
    if (respawnHere) {
      logDebug(player, "    Respawn local");
    }
    if (celestialAngle != null) {
      logDebug(player, "    Celestial angle: " + celestialAngle);
    }
    if (timeSpeed != null) {
      logDebug(player, "    Time speed: " + timeSpeed);
    }
    if (probeCounter > 0) {
      logDebug(player, "    Probes: " + probeCounter);
    }
    if (patreon1 != 0) {
      logDebug(player, "    Patreon: " + patreon1);
    }
  }
  public void toBytes(ByteBuf buf) {
    NetworkTools.writeEnum(buf, terrainType, TerrainType.TERRAIN_VOID);
    NetworkTools.writeEnumCollection(buf, featureTypes);
    NetworkTools.writeEnumCollection(buf, structureTypes);
    NetworkTools.writeEnumCollection(buf, effectTypes);

    buf.writeInt(biomes.size());
    for (BiomeGenBase entry : biomes) {
      if (entry != null) {
        buf.writeInt(entry.biomeID);
      } else {
        buf.writeInt(BiomeGenBase.plains.biomeID);
      }
    }
    NetworkTools.writeEnum(buf, controllerType, ControllerType.CONTROLLER_DEFAULT);

    NetworkTools.writeString(buf, digitString);
    buf.writeLong(forcedDimensionSeed);
    buf.writeLong(baseSeed);
    buf.writeInt(worldVersion);

    buf.writeInt(Block.blockRegistry.getIDForObject(baseBlockForTerrain.getBlock()));
    buf.writeInt(baseBlockForTerrain.getMeta());
    buf.writeInt(Block.blockRegistry.getIDForObject(tendrilBlock.getBlock()));
    buf.writeInt(tendrilBlock.getMeta());

    writeBlockArrayToBuf(buf, pyramidBlocks);
    writeBlockArrayToBuf(buf, sphereBlocks);
    writeBlockArrayToBuf(buf, hugeSphereBlocks);
    writeBlockArrayToBuf(buf, liquidSphereBlocks);
    writeFluidArrayToBuf(buf, liquidSphereFluids);
    writeBlockArrayToBuf(buf, hugeLiquidSphereBlocks);
    writeFluidArrayToBuf(buf, hugeLiquidSphereFluids);

    buf.writeInt(Block.blockRegistry.getIDForObject(canyonBlock.getBlock()));
    buf.writeInt(canyonBlock.getMeta());
    buf.writeInt(Block.blockRegistry.getIDForObject(fluidForTerrain));

    writeBlockArrayToBuf(buf, extraOregen);

    writeFluidArrayToBuf(buf, fluidsForLakes);

    buf.writeBoolean(peaceful);
    buf.writeBoolean(noanimals);
    buf.writeBoolean(shelter);
    buf.writeBoolean(respawnHere);
    NetworkTools.writeFloat(buf, celestialAngle);
    NetworkTools.writeFloat(buf, timeSpeed);

    buf.writeInt(probeCounter);
    buf.writeInt(actualRfCost);

    skyDescriptor.toBytes(buf);
    weatherDescriptor.toBytes(buf);

    buf.writeLong(patreon1);

    buf.writeInt(extraMobs.size());
    for (MobDescriptor mob : extraMobs) {
      if (mob != null) {
        if (mob.getEntityClass() != null) {
          NetworkTools.writeString(buf, mob.getEntityClass().getName());
          buf.writeInt(mob.getSpawnChance());
          buf.writeInt(mob.getMinGroup());
          buf.writeInt(mob.getMaxGroup());
          buf.writeInt(mob.getMaxLoaded());
        }
      }
    }

    buf.writeInt(dimensionTypes.length);
    for (String type : dimensionTypes) {
      NetworkTools.writeString(buf, type);
    }
  }
  public void writeToNBT(NBTTagCompound tagCompound) {
    tagCompound.setString("name", getName());
    Coordinate spawnPoint = getSpawnPoint();
    if (spawnPoint != null) {
      Coordinate.writeToNBT(tagCompound, "spawnPoint", spawnPoint);
    }
    tagCompound.setInteger("probeCounter", getProbeCounter());
    tagCompound.setInteger(
        "version",
        1); // Version number so that we can detect incompatible changes in persisted dimension
    // information objects.

    tagCompound.setInteger(
        "terrain",
        terrainType == null ? TerrainType.TERRAIN_VOID.ordinal() : terrainType.ordinal());
    tagCompound.setIntArray("features", toIntArray(featureTypes));
    tagCompound.setIntArray("structures", toIntArray(structureTypes));
    tagCompound.setIntArray("effects", toIntArray(effectTypes));

    List<Integer> c = new ArrayList<Integer>(biomes.size());
    for (BiomeGenBase t : biomes) {
      if (t != null) {
        c.add(t.biomeID);
      } else {
        c.add(BiomeGenBase.plains.biomeID);
      }
    }
    tagCompound.setIntArray("biomes", ArrayUtils.toPrimitive(c.toArray(new Integer[c.size()])));
    tagCompound.setInteger(
        "controller",
        controllerType == null
            ? ControllerType.CONTROLLER_DEFAULT.ordinal()
            : controllerType.ordinal());
    tagCompound.setString("digits", digitString);

    tagCompound.setLong("forcedSeed", forcedDimensionSeed);
    tagCompound.setLong("baseSeed", baseSeed);
    tagCompound.setInteger("worldVersion", worldVersion);

    setBlockMeta(tagCompound, baseBlockForTerrain, "baseBlock");
    setBlockMeta(tagCompound, tendrilBlock, "tendrilBlock");

    writeBlocksToNBT(tagCompound, pyramidBlocks, "pyramidBlocks");

    writeBlocksToNBT(tagCompound, sphereBlocks, "sphereBlocks");
    if (sphereBlocks.length > 0) {
      // Write out a single sphere block for compatibility with older RFTools.
      setBlockMeta(tagCompound, sphereBlocks[0], "sphereBlock");
    }

    writeBlocksToNBT(tagCompound, hugeSphereBlocks, "hugeSphereBlocks");
    writeBlocksToNBT(tagCompound, hugeLiquidSphereBlocks, "hugeLiquidSphereBlocks");
    writeFluidsToNBT(tagCompound, hugeLiquidSphereFluids, "hugeLiquidSphereFluids");

    writeBlocksToNBT(tagCompound, liquidSphereBlocks, "liquidSphereBlocks");
    if (liquidSphereBlocks.length > 0) {
      // Write out a single sphere block for compatibility with older RFTools.
      setBlockMeta(tagCompound, liquidSphereBlocks[0], "liquidSphereBlock");
    }

    writeFluidsToNBT(tagCompound, liquidSphereFluids, "liquidSphereFluids");
    if (liquidSphereFluids.length > 0) {
      tagCompound.setInteger(
          "liquidSphereFluid", Block.blockRegistry.getIDForObject(liquidSphereFluids[0]));
    }

    setBlockMeta(tagCompound, canyonBlock, "canyonBlock");
    tagCompound.setInteger("fluidBlock", Block.blockRegistry.getIDForObject(fluidForTerrain));

    writeBlocksToNBT(tagCompound, extraOregen, "extraOregen");
    writeFluidsToNBT(tagCompound, fluidsForLakes, "lakeFluids");

    tagCompound.setBoolean("peaceful", peaceful);
    tagCompound.setBoolean("noanimals", noanimals);
    tagCompound.setBoolean("shelter", shelter);
    tagCompound.setBoolean("respawnHere", respawnHere);
    if (celestialAngle != null) {
      tagCompound.setFloat("celestialAngle", celestialAngle);
    }
    if (timeSpeed != null) {
      tagCompound.setFloat("timeSpeed", timeSpeed);
    }
    tagCompound.setInteger("probes", probeCounter);
    tagCompound.setInteger("actualCost", actualRfCost);

    skyDescriptor.writeToNBT(tagCompound);
    weatherDescriptor.writeToNBT(tagCompound);

    tagCompound.setLong("patreon1", patreon1);

    NBTTagList list = new NBTTagList();
    for (MobDescriptor mob : extraMobs) {
      NBTTagCompound tc = new NBTTagCompound();

      if (mob != null) {
        if (mob.getEntityClass() != null) {
          tc.setString("class", mob.getEntityClass().getName());
          tc.setInteger("chance", mob.getSpawnChance());
          tc.setInteger("minGroup", mob.getMinGroup());
          tc.setInteger("maxGroup", mob.getMaxGroup());
          tc.setInteger("maxLoaded", mob.getMaxLoaded());
          list.appendTag(tc);
        }
      }
    }

    tagCompound.setTag("mobs", list);
    tagCompound.setString("dimensionTypes", StringUtils.join(dimensionTypes, ","));
  }