/** Gets the amount of light on a block taking into account sunlight */
  public int getBlockLightValue(int par1, int par2, int par3, int par4) {
    ExtendedBlockStorage var5 = this.storageArrays[par2 >> 4];

    if (var5 == null) {
      return !this.worldObj.provider.hasNoSky && par4 < EnumSkyBlock.Sky.defaultLightValue
          ? EnumSkyBlock.Sky.defaultLightValue - par4
          : 0;
    } else {
      int var6 =
          this.worldObj.provider.hasNoSky ? 0 : var5.getExtSkylightValue(par1, par2 & 15, par3);

      if (var6 > 0) {
        isLit = true;
      }

      var6 -= par4;
      int var7 = var5.getExtBlocklightValue(par1, par2 & 15, par3);

      if (var7 > var6) {
        var6 = var7;
      }

      return var6;
    }
  }
  /** Set the metadata of a block in the chunk */
  public boolean setBlockMetadata(int par1, int par2, int par3, int par4) {
    ExtendedBlockStorage var5 = this.storageArrays[par2 >> 4];

    if (var5 == null) {
      return false;
    } else {
      int var6 = var5.getExtBlockMetadata(par1, par2 & 15, par3);

      if (var6 == par4) {
        return false;
      } else {
        this.isModified = true;
        var5.setExtBlockMetadata(par1, par2 & 15, par3, par4);
        int var7 = var5.getExtBlockID(par1, par2 & 15, par3);

        if (var7 > 0 && Block.blocksList[var7] instanceof ITileEntityProvider) {
          TileEntity var8 = this.getChunkBlockTileEntity(par1, par2, par3);

          if (var8 != null) {
            var8.updateContainingBlockInfo();
            var8.blockMetadata = par4;
          }
        }

        return true;
      }
    }
  }
 /** Return the metadata corresponding to the given coordinates inside a chunk. */
 public int getBlockMetadata(int par1, int par2, int par3) {
   if (par2 >> 4 >= this.storageArrays.length) {
     return 0;
   } else {
     ExtendedBlockStorage var4 = this.storageArrays[par2 >> 4];
     return var4 != null ? var4.getExtBlockMetadata(par1, par2 & 15, par3) : 0;
   }
 }
 /** Gets the amount of light saved in this block (doesn't adjust for daylight) */
 public int getSavedLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4) {
   ExtendedBlockStorage var5 = this.storageArrays[par3 >> 4];
   return var5 == null
       ? (this.canBlockSeeTheSky(par2, par3, par4) ? par1EnumSkyBlock.defaultLightValue : 0)
       : (par1EnumSkyBlock == EnumSkyBlock.Sky
           ? (this.worldObj.provider.hasNoSky
               ? 0
               : var5.getExtSkylightValue(par2, par3 & 15, par4))
           : (par1EnumSkyBlock == EnumSkyBlock.Block
               ? var5.getExtBlocklightValue(par2, par3 & 15, par4)
               : par1EnumSkyBlock.defaultLightValue));
 }
  /**
   * Returns whether the ExtendedBlockStorages containing levels (in blocks) from arg 1 to arg 2 are
   * fully empty (true) or not (false).
   */
  public boolean getAreLevelsEmpty(int par1, int par2) {
    if (par1 < 0) {
      par1 = 0;
    }

    if (par2 >= 256) {
      par2 = 255;
    }

    for (int var3 = par1; var3 <= par2; var3 += 16) {
      ExtendedBlockStorage var4 = this.storageArrays[var3 >> 4];

      if (var4 != null && !var4.isEmpty()) {
        return false;
      }
    }

    return true;
  }
  /**
   * Sets the light value at the coordinate. If enumskyblock is set to sky it sets it in the
   * skylightmap and if its a block then into the blocklightmap. Args enumSkyBlock, x, y, z,
   * lightValue
   */
  public void setLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4, int par5) {
    ExtendedBlockStorage var6 = this.storageArrays[par3 >> 4];

    if (var6 == null) {
      var6 =
          this.storageArrays[par3 >> 4] =
              new ExtendedBlockStorage(par3 >> 4 << 4, !this.worldObj.provider.hasNoSky);
      this.generateSkylightMap();
    }

    this.isModified = true;

    if (par1EnumSkyBlock == EnumSkyBlock.Sky) {
      if (!this.worldObj.provider.hasNoSky) {
        var6.setExtSkylightValue(par2, par3 & 15, par4, par5);
      }
    } else if (par1EnumSkyBlock == EnumSkyBlock.Block) {
      var6.setExtBlocklightValue(par2, par3 & 15, par4, par5);
    }
  }
  /**
   * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the
   * blocks for the specified chunk from the map seed and chunk seed
   */
  public Chunk provideChunk(int par1, int par2) {
    Chunk var3 = new Chunk(this.worldObj, par1, par2);

    for (int var4 = 0; var4 < this.field_82700_c.length; ++var4) {
      int var5 = var4 >> 4;
      ExtendedBlockStorage var6 = var3.getBlockStorageArray()[var5];

      if (var6 == null) {
        var6 = new ExtendedBlockStorage(var4, !this.worldObj.provider.hasNoSky);
        var3.getBlockStorageArray()[var5] = var6;
      }

      for (int var7 = 0; var7 < 16; ++var7) {
        for (int var8 = 0; var8 < 16; ++var8) {
          var6.setExtBlockID(var7, var4 & 15, var8, this.field_82700_c[var4] & 255);
          var6.setExtBlockMetadata(var7, var4 & 15, var8, this.field_82698_d[var4]);
        }
      }
    }

    var3.generateSkylightMap();
    BiomeGenBase[] var9 =
        this.worldObj
            .getWorldChunkManager()
            .loadBlockGeneratorData((BiomeGenBase[]) null, par1 * 16, par2 * 16, 16, 16);
    byte[] var10 = var3.getBiomeArray();

    for (int var11 = 0; var11 < var10.length; ++var11) {
      var10[var11] = (byte) var9[var11].biomeID;
    }

    Iterator var12 = this.structureGenerators.iterator();

    while (var12.hasNext()) {
      MapGenStructure var13 = (MapGenStructure) var12.next();
      var13.generate(this, this.worldObj, par1, par2, (byte[]) null);
    }

    var3.generateSkylightMap();
    return var3;
  }
  /** Sets a blockID of a position within a chunk with metadata. Args: x, y, z, blockID, metadata */
  public boolean setBlockIDWithMetadata(int par1, int par2, int par3, int par4, int par5) {
    int var6 = par3 << 4 | par1;

    if (par2 >= this.precipitationHeightMap[var6] - 1) {
      this.precipitationHeightMap[var6] = -999;
    }

    int var7 = this.heightMap[var6];
    int var8 = this.getBlockID(par1, par2, par3);
    int var9 = this.getBlockMetadata(par1, par2, par3);

    if (var8 == par4 && var9 == par5) {
      return false;
    } else {
      ExtendedBlockStorage var10 = this.storageArrays[par2 >> 4];
      boolean var11 = false;

      if (var10 == null) {
        if (par4 == 0) {
          return false;
        }

        var10 =
            this.storageArrays[par2 >> 4] =
                new ExtendedBlockStorage(par2 >> 4 << 4, !this.worldObj.provider.hasNoSky);
        var11 = par2 >= var7;
      }

      int var12 = this.xPosition * 16 + par1;
      int var13 = this.zPosition * 16 + par3;

      if (var8 != 0 && !this.worldObj.isRemote) {
        Block.blocksList[var8].onSetBlockIDWithMetaData(this.worldObj, var12, par2, var13, var9);
      }

      var10.setExtBlockID(par1, par2 & 15, par3, par4);

      if (var8 != 0) {
        if (!this.worldObj.isRemote) {
          Block.blocksList[var8].breakBlock(this.worldObj, var12, par2, var13, var8, var9);
        } else if (Block.blocksList[var8] instanceof ITileEntityProvider && var8 != par4) {
          this.worldObj.removeBlockTileEntity(var12, par2, var13);
        }
      }

      if (var10.getExtBlockID(par1, par2 & 15, par3) != par4) {
        return false;
      } else {
        var10.setExtBlockMetadata(par1, par2 & 15, par3, par5);

        if (var11) {
          this.generateSkylightMap();
        } else {
          if (Block.lightOpacity[par4 & 4095] > 0) {
            if (par2 >= var7) {
              this.relightBlock(par1, par2 + 1, par3);
            }
          } else if (par2 == var7 - 1) {
            this.relightBlock(par1, par2, par3);
          }

          this.propagateSkylightOcclusion(par1, par3);
        }

        TileEntity var14;

        if (par4 != 0) {
          if (!this.worldObj.isRemote) {
            Block.blocksList[par4].onBlockAdded(this.worldObj, var12, par2, var13);
          }

          if (Block.blocksList[par4] instanceof ITileEntityProvider) {
            var14 = this.getChunkBlockTileEntity(par1, par2, par3);

            if (var14 == null) {
              var14 =
                  ((ITileEntityProvider) Block.blocksList[par4]).createNewTileEntity(this.worldObj);
              this.worldObj.setBlockTileEntity(var12, par2, var13, var14);
            }

            if (var14 != null) {
              var14.updateContainingBlockInfo();
            }
          }
        } else if (var8 > 0 && Block.blocksList[var8] instanceof ITileEntityProvider) {
          var14 = this.getChunkBlockTileEntity(par1, par2, par3);

          if (var14 != null) {
            var14.updateContainingBlockInfo();
          }
        }

        this.isModified = true;
        return true;
      }
    }
  }
  /**
   * Initiates the recalculation of both the block-light and sky-light for a given block inside a
   * chunk.
   */
  private void relightBlock(int par1, int par2, int par3) {
    int var4 = this.heightMap[par3 << 4 | par1] & 255;
    int var5 = var4;

    if (par2 > var4) {
      var5 = par2;
    }

    while (var5 > 0 && this.getBlockLightOpacity(par1, var5 - 1, par3) == 0) {
      --var5;
    }

    if (var5 != var4) {
      this.worldObj.markBlocksDirtyVertical(
          par1 + this.xPosition * 16, par3 + this.zPosition * 16, var5, var4);
      this.heightMap[par3 << 4 | par1] = var5;
      int var6 = this.xPosition * 16 + par1;
      int var7 = this.zPosition * 16 + par3;
      int var8;
      int var12;

      if (!this.worldObj.provider.hasNoSky) {
        ExtendedBlockStorage var9;

        if (var5 < var4) {
          for (var8 = var5; var8 < var4; ++var8) {
            var9 = this.storageArrays[var8 >> 4];

            if (var9 != null) {
              var9.setExtSkylightValue(par1, var8 & 15, par3, 15);
              this.worldObj.markBlockForRenderUpdate(
                  (this.xPosition << 4) + par1, var8, (this.zPosition << 4) + par3);
            }
          }
        } else {
          for (var8 = var4; var8 < var5; ++var8) {
            var9 = this.storageArrays[var8 >> 4];

            if (var9 != null) {
              var9.setExtSkylightValue(par1, var8 & 15, par3, 0);
              this.worldObj.markBlockForRenderUpdate(
                  (this.xPosition << 4) + par1, var8, (this.zPosition << 4) + par3);
            }
          }
        }

        var8 = 15;

        while (var5 > 0 && var8 > 0) {
          --var5;
          var12 = this.getBlockLightOpacity(par1, var5, par3);

          if (var12 == 0) {
            var12 = 1;
          }

          var8 -= var12;

          if (var8 < 0) {
            var8 = 0;
          }

          ExtendedBlockStorage var10 = this.storageArrays[var5 >> 4];

          if (var10 != null) {
            var10.setExtSkylightValue(par1, var5 & 15, par3, var8);
          }
        }
      }

      var8 = this.heightMap[par3 << 4 | par1];
      var12 = var4;
      int var13 = var8;

      if (var8 < var4) {
        var12 = var8;
        var13 = var4;
      }

      if (var8 < this.field_82912_p) {
        this.field_82912_p = var8;
      }

      if (!this.worldObj.provider.hasNoSky) {
        this.updateSkylightNeighborHeight(var6 - 1, var7, var12, var13);
        this.updateSkylightNeighborHeight(var6 + 1, var7, var12, var13);
        this.updateSkylightNeighborHeight(var6, var7 - 1, var12, var13);
        this.updateSkylightNeighborHeight(var6, var7 + 1, var12, var13);
        this.updateSkylightNeighborHeight(var6, var7, var12, var13);
      }

      this.isModified = true;
    }
  }
  /** Generates the initial skylight map for the chunk upon generation or load. */
  public void generateSkylightMap() {
    int var1 = this.getTopFilledSegment();
    this.field_82912_p = Integer.MAX_VALUE;
    int var2;
    int var3;

    for (var2 = 0; var2 < 16; ++var2) {
      var3 = 0;

      while (var3 < 16) {
        this.precipitationHeightMap[var2 + (var3 << 4)] = -999;
        int var4 = var1 + 16 - 1;

        while (true) {
          if (var4 > 0) {
            if (this.getBlockLightOpacity(var2, var4 - 1, var3) == 0) {
              --var4;
              continue;
            }

            this.heightMap[var3 << 4 | var2] = var4;

            if (var4 < this.field_82912_p) {
              this.field_82912_p = var4;
            }
          }

          if (!this.worldObj.provider.hasNoSky) {
            var4 = 15;
            int var5 = var1 + 16 - 1;

            do {
              var4 -= this.getBlockLightOpacity(var2, var5, var3);

              if (var4 > 0) {
                ExtendedBlockStorage var6 = this.storageArrays[var5 >> 4];

                if (var6 != null) {
                  var6.setExtSkylightValue(var2, var5 & 15, var3, var4);
                  this.worldObj.markBlockForRenderUpdate(
                      (this.xPosition << 4) + var2, var5, (this.zPosition << 4) + var3);
                }
              }

              --var5;
            } while (var5 > 0 && var4 > 0);
          }

          ++var3;
          break;
        }
      }
    }

    this.isModified = true;

    for (var2 = 0; var2 < 16; ++var2) {
      for (var3 = 0; var3 < 16; ++var3) {
        this.propagateSkylightOcclusion(var2, var3);
      }
    }
  }
Beispiel #11
0
  /**
   * plays random cave ambient sounds and runs updateTick on random blocks within each chunk in the
   * vacinity of a player
   */
  protected void tickBlocksAndAmbiance() {
    super.tickBlocksAndAmbiance();
    int var1 = 0;
    int var2 = 0;
    Iterator var3 = this.activeChunkSet.iterator();

    while (var3.hasNext()) {
      ChunkCoordIntPair var4 = (ChunkCoordIntPair) var3.next();
      int var5 = var4.chunkXPos * 16;
      int var6 = var4.chunkZPos * 16;
      this.theProfiler.startSection("getChunk");
      Chunk var7 = this.getChunkFromChunkCoords(var4.chunkXPos, var4.chunkZPos);
      this.moodSoundAndLightCheck(var5, var6, var7);
      this.theProfiler.endStartSection("tickChunk");
      var7.updateSkylight();
      this.theProfiler.endStartSection("thunder");
      int var8;
      int var9;
      int var10;
      int var11;

      if (this.rand.nextInt(100000) == 0 && this.isRaining() && this.isThundering()) {
        this.updateLCG = this.updateLCG * 3 + 1013904223;
        var8 = this.updateLCG >> 2;
        var9 = var5 + (var8 & 15);
        var10 = var6 + (var8 >> 8 & 15);
        var11 = this.getPrecipitationHeight(var9, var10);

        if (this.canLightningStrikeAt(var9, var11, var10)) {
          this.addWeatherEffect(
              new EntityLightningBolt(this, (double) var9, (double) var11, (double) var10));
        }
      }

      this.theProfiler.endStartSection("iceandsnow");
      int var13;

      if (this.rand.nextInt(16) == 0) {
        this.updateLCG = this.updateLCG * 3 + 1013904223;
        var8 = this.updateLCG >> 2;
        var9 = var8 & 15;
        var10 = var8 >> 8 & 15;
        var11 = this.getPrecipitationHeight(var9 + var5, var10 + var6);

        if (this.isBlockFreezableNaturally(var9 + var5, var11 - 1, var10 + var6)) {
          this.setBlock(var9 + var5, var11 - 1, var10 + var6, Block.ice.blockID);
        }

        if (this.isRaining() && this.canSnowAt(var9 + var5, var11, var10 + var6)) {
          this.setBlock(var9 + var5, var11, var10 + var6, Block.snow.blockID);
        }

        if (this.isRaining()) {
          BiomeGenBase var12 = this.getBiomeGenForCoords(var9 + var5, var10 + var6);

          if (var12.canSpawnLightningBolt()) {
            var13 = this.getBlockId(var9 + var5, var11 - 1, var10 + var6);

            if (var13 != 0) {
              Block.blocksList[var13].fillWithRain(this, var9 + var5, var11 - 1, var10 + var6);
            }
          }
        }
      }

      this.theProfiler.endStartSection("tickTiles");
      ExtendedBlockStorage[] var19 = var7.getBlockStorageArray();
      var9 = var19.length;

      for (var10 = 0; var10 < var9; ++var10) {
        ExtendedBlockStorage var21 = var19[var10];

        if (var21 != null && var21.getNeedsRandomTick()) {
          for (int var20 = 0; var20 < 3; ++var20) {
            this.updateLCG = this.updateLCG * 3 + 1013904223;
            var13 = this.updateLCG >> 2;
            int var14 = var13 & 15;
            int var15 = var13 >> 8 & 15;
            int var16 = var13 >> 16 & 15;
            int var17 = var21.getExtBlockID(var14, var16, var15);
            ++var2;
            Block var18 = Block.blocksList[var17];

            if (var18 != null && var18.getTickRandomly()) {
              ++var1;
              var18.updateTick(
                  this, var14 + var5, var16 + var21.getYLocation(), var15 + var6, this.rand);
            }
          }
        }
      }

      this.theProfiler.endSection();
    }
  }