@HawkEvent(dataType = {DataType.LAVA_FLOW, DataType.WATER_FLOW})
  public void onBlockFromTo(BlockFromToEvent event) {
    List<Integer> fluidBlocks =
        Arrays.asList(
            0, 27, 28, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 69, 70, 75, 76, 78, 93, 94);

    Location loc = event.getToBlock().getLocation();
    BlockState from = event.getBlock().getState();
    BlockState to = event.getToBlock().getState();
    MaterialData data = from.getData();

    // Lava
    if (from.getTypeId() == 10 || from.getTypeId() == 11) {

      // Flowing into a normal block
      if (fluidBlocks.contains(to.getTypeId())) {
        data.setData((byte) (from.getRawData() + 1));
        from.setData(data);
      }

      // Flowing into water
      else if (to.getTypeId() == 8 || to.getTypeId() == 9) {
        from.setTypeId(event.getFace() == BlockFace.DOWN ? 10 : 4);
        data.setData((byte) 0);
        from.setData(data);
      }
      DataManager.addEntry(new BlockChangeEntry("Environment", DataType.LAVA_FLOW, loc, to, from));

    }

    // Water
    else if (from.getTypeId() == 8 || from.getTypeId() == 9) {

      // Normal block
      if (fluidBlocks.contains(to.getTypeId())) {
        data.setData((byte) (from.getRawData() + 1));
        from.setData(data);
        DataManager.addEntry(
            new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, to, from));
      }

      // If we are flowing over lava, cobble or obsidian will form
      BlockState lower = event.getToBlock().getRelative(BlockFace.DOWN).getState();
      if (lower.getTypeId() == 10 || lower.getTypeId() == 11) {
        from.setTypeId(lower.getData().getData() == 0 ? 49 : 4);
        loc.setY(loc.getY() - 1);
        DataManager.addEntry(
            new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, lower, from));
      }
    }
  }
  /** BlockFadeEvent */
  public static BlockFadeEvent callBlockFadeEvent(Block block, int type) {
    BlockState state = block.getState();
    state.setTypeId(type);

    BlockFadeEvent event = new BlockFadeEvent(block, state);
    Bukkit.getPluginManager().callEvent(event);
    return event;
  }
Пример #3
0
  public void a(World world, int i, int j, int k, Random random) {
    if (random.nextInt(25) == 0) {
      byte b0 = 4;
      int l = 5;

      int i1;
      int j1;
      int k1;

      for (i1 = i - b0; i1 <= i + b0; ++i1) {
        for (j1 = k - b0; j1 <= k + b0; ++j1) {
          for (k1 = j - 1; k1 <= j + 1; ++k1) {
            if (world.getTypeId(i1, k1, j1) == this.id) {
              --l;
              if (l <= 0) {
                return;
              }
            }
          }
        }
      }

      i1 = i + random.nextInt(3) - 1;
      j1 = j + random.nextInt(2) - random.nextInt(2);
      k1 = k + random.nextInt(3) - 1;

      for (int l1 = 0; l1 < 4; ++l1) {
        if (world.isEmpty(i1, j1, k1) && this.f(world, i1, j1, k1)) {
          i = i1;
          j = j1;
          k = k1;
        }

        i1 = i + random.nextInt(3) - 1;
        j1 = j + random.nextInt(2) - random.nextInt(2);
        k1 = k + random.nextInt(3) - 1;
      }

      if (world.isEmpty(i1, j1, k1) && this.f(world, i1, j1, k1)) {
        // lightstone start
        org.bukkit.World bworld = world.getWorld();
        org.bukkit.block.BlockState blockState = bworld.getBlockAt(i1, j1, k1).getState();
        blockState.setTypeId(this.id);

        BlockSpreadEvent event =
            new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(i, j, k), blockState);
        world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
          blockState.update(true);
        }
        // lightstone end
      }
    }
  }
Пример #4
0
  protected void g() {
    super.g();
    int i = 0;
    int j = 0;
    // CraftBukkit start
    // Iterator iterator = this.chunkTickList.iterator();

    for (long chunkCoord : this.chunkTickList.popAll()) {
      int chunkX = LongHash.msw(chunkCoord);
      int chunkZ = LongHash.lsw(chunkCoord);
      // ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next();
      int k = chunkX * 16;
      int l = chunkZ * 16;

      this.methodProfiler.a("getChunk");
      Chunk chunk = this.getChunkAt(chunkX, chunkZ);
      // CraftBukkit end

      this.a(k, l, chunk);
      this.methodProfiler.c("tickChunk");
      chunk.k();
      this.methodProfiler.c("thunder");
      int i1;
      int j1;
      int k1;
      int l1;

      if (this.random.nextInt(100000) == 0 && this.Q() && this.P()) {
        this.k = this.k * 3 + 1013904223;
        i1 = this.k >> 2;
        j1 = k + (i1 & 15);
        k1 = l + (i1 >> 8 & 15);
        l1 = this.h(j1, k1);
        if (this.isRainingAt(j1, l1, k1)) {
          this.strikeLightning(new EntityLightning(this, (double) j1, (double) l1, (double) k1));
        }
      }

      this.methodProfiler.c("iceandsnow");
      int i2;

      if (this.random.nextInt(16) == 0) {
        this.k = this.k * 3 + 1013904223;
        i1 = this.k >> 2;
        j1 = i1 & 15;
        k1 = i1 >> 8 & 15;
        l1 = this.h(j1 + k, k1 + l);
        if (this.y(j1 + k, l1 - 1, k1 + l)) {
          // CraftBukkit start
          BlockState blockState = this.getWorld().getBlockAt(j1 + k, l1 - 1, k1 + l).getState();
          blockState.setTypeId(Block.ICE.id);

          BlockFormEvent iceBlockForm = new BlockFormEvent(blockState.getBlock(), blockState);
          this.getServer().getPluginManager().callEvent(iceBlockForm);
          if (!iceBlockForm.isCancelled()) {
            blockState.update(true);
          }
          // CraftBukkit end
        }

        if (this.Q() && this.z(j1 + k, l1, k1 + l)) {
          // CraftBukkit start
          BlockState blockState = this.getWorld().getBlockAt(j1 + k, l1, k1 + l).getState();
          blockState.setTypeId(Block.SNOW.id);

          BlockFormEvent snow = new BlockFormEvent(blockState.getBlock(), blockState);
          this.getServer().getPluginManager().callEvent(snow);
          if (!snow.isCancelled()) {
            blockState.update(true);
          }
          // CraftBukkit end
        }

        if (this.Q()) {
          BiomeBase biomebase = this.getBiome(j1 + k, k1 + l);

          if (biomebase.d()) {
            i2 = this.getTypeId(j1 + k, l1 - 1, k1 + l);
            if (i2 != 0) {
              Block.byId[i2].g(this, j1 + k, l1 - 1, k1 + l);
            }
          }
        }
      }

      this.methodProfiler.c("tickTiles");
      ChunkSection[] achunksection = chunk.i();

      j1 = achunksection.length;

      for (k1 = 0; k1 < j1; ++k1) {
        ChunkSection chunksection = achunksection[k1];

        if (chunksection != null && chunksection.shouldTick()) {
          for (int j2 = 0; j2 < 3; ++j2) {
            this.k = this.k * 3 + 1013904223;
            i2 = this.k >> 2;
            int k2 = i2 & 15;
            int l2 = i2 >> 8 & 15;
            int i3 = i2 >> 16 & 15;
            int j3 = chunksection.getTypeId(k2, i3, l2);

            ++j;
            Block block = Block.byId[j3];

            if (block != null && block.isTicking()) {
              ++i;
              block.a(this, k2 + k, i3 + chunksection.getYPosition(), l2 + l, this.random);
            }
          }
        }
      }

      this.methodProfiler.b();
    }
  }