Example #1
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
      }
    }
  }
  public boolean generate(World world, Random random, BlockPosition blockposition) {
    while (world.isEmpty(blockposition) && blockposition.getY() > 2) {
      blockposition = blockposition.down();
    }

    if (world.getType(blockposition).getBlock() != Blocks.SNOW) {
      return false;
    } else {
      int i = random.nextInt(this.b - 2) + 2;
      byte b0 = 1;

      for (int j = blockposition.getX() - i; j <= blockposition.getX() + i; ++j) {
        for (int k = blockposition.getZ() - i; k <= blockposition.getZ() + i; ++k) {
          int l = j - blockposition.getX();
          int i1 = k - blockposition.getZ();

          if (l * l + i1 * i1 <= i * i) {
            for (int j1 = blockposition.getY() - b0; j1 <= blockposition.getY() + b0; ++j1) {
              BlockPosition blockposition1 = new BlockPosition(j, j1, k);
              Block block = world.getType(blockposition1).getBlock();

              if (block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE) {
                world.setTypeAndData(blockposition1, this.a.getBlockData(), 2);
              }
            }
          }
        }
      }

      return true;
    }
  }
Example #3
0
  public boolean interactWith(
      ItemStack itemstack,
      EntityHuman entityhuman,
      World world,
      int i,
      int j,
      int k,
      int l,
      float f,
      float f1,
      float f2) {
    if (world.getTypeId(i, j, k) != Block.SNOW.id) {
      if (l == 0) {
        --j;
      }

      if (l == 1) {
        ++j;
      }

      if (l == 2) {
        --k;
      }

      if (l == 3) {
        ++k;
      }

      if (l == 4) {
        --i;
      }

      if (l == 5) {
        ++i;
      }

      if (!world.isEmpty(i, j, k)) {
        return false;
      }
    }

    if (!entityhuman.a(i, j, k, l, itemstack)) {
      return false;
    } else {
      if (Block.REDSTONE_WIRE.canPlace(world, i, j, k)) {
        --itemstack.count;
        world.setTypeIdUpdate(i, j, k, Block.REDSTONE_WIRE.id);
      }

      return true;
    }
  }
Example #4
0
  public boolean generate(World world, Random random, BlockPosition blockposition) {
    for (int i = 0; i < 64; ++i) {
      BlockPosition blockposition1 =
          blockposition.a(
              random.nextInt(8) - random.nextInt(8),
              random.nextInt(4) - random.nextInt(4),
              random.nextInt(8) - random.nextInt(8));

      if (world.isEmpty(blockposition1)
          && world.getType(blockposition1.down()).getBlock() == Blocks.NETHERRACK) {
        world.setTypeAndData(blockposition1, Blocks.FIRE.getBlockData(), 2);
      }
    }

    return true;
  }
Example #5
0
  public boolean generate(World world, Random random, int i, int j, int k) {
    Block block;

    while (((block = world.getType(i, j, k)).getMaterial() == Material.AIR
            || block.getMaterial() == Material.LEAVES)
        && j > 0) {
      --j;
    }

    for (int l = 0; l < 128; ++l) {
      int i1 = i + random.nextInt(8) - random.nextInt(8);
      int j1 = j + random.nextInt(4) - random.nextInt(4);
      int k1 = k + random.nextInt(8) - random.nextInt(8);

      if (world.isEmpty(i1, j1, k1) && this.a.j(world, i1, j1, k1)) {
        world.setTypeAndData(i1, j1, k1, this.a, this.b, 2);
      }
    }

    return true;
  }
  public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
    ItemBucket itembucket = (ItemBucket) itemstack.getItem();
    BlockPosition blockposition =
        isourceblock.getBlockPosition().shift(BlockDispenser.b(isourceblock.f()));

    // CraftBukkit start
    World world = isourceblock.i();
    int x = blockposition.getX();
    int y = blockposition.getY();
    int z = blockposition.getZ();
    if (world.isEmpty(blockposition)
        || !world.getType(blockposition).getBlock().getMaterial().isBuildable()) {
      org.bukkit.block.Block block =
          world
              .getWorld()
              .getBlockAt(
                  isourceblock.getBlockPosition().getX(),
                  isourceblock.getBlockPosition().getY(),
                  isourceblock.getBlockPosition().getZ());
      CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);

      BlockDispenseEvent event =
          new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(x, y, z));
      if (!BlockDispenser.eventFired) {
        world.getServer().getPluginManager().callEvent(event);
      }

      if (event.isCancelled()) {
        return itemstack;
      }

      if (!event.getItem().equals(craftItem)) {
        // Chain to handler for new item
        ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
        IDispenseBehavior idispensebehavior =
            (IDispenseBehavior) BlockDispenser.M.get(eventStack.getItem());
        if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
          idispensebehavior.a(isourceblock, eventStack);
          return itemstack;
        }
      }

      itembucket = (ItemBucket) CraftItemStack.asNMSCopy(event.getItem()).getItem();
    }
    // CraftBukkit end

    if (itembucket.a(isourceblock.i(), blockposition)) {
      // CraftBukkit start - Handle stacked buckets
      Item item = Items.BUCKET;
      if (--itemstack.count == 0) {
        itemstack.setItem(Items.BUCKET);
        itemstack.count = 1;
      } else if (((TileEntityDispenser) isourceblock.getTileEntity()).addItem(new ItemStack(item))
          < 0) {
        this.b.a(isourceblock, new ItemStack(item));
      }
      // CraftBukkit end
      return itemstack;
    } else {
      return this.b.a(isourceblock, itemstack);
    }
  }
  public UseResult interactWith(
      ItemStack var1,
      EntityHuman var2,
      World var3,
      BlockPosition var4,
      EnumUsedHand var5,
      EnumDirection var6,
      float var7,
      float var8,
      float var9) {
    if (var6 == EnumDirection.DOWN) {
      return UseResult.CANT_USE;
    } else {
      boolean var10 = var3.getType(var4).getBlock().isReplaceable(var3, var4);
      BlockPosition var11 = var10 ? var4 : var4.shift(var6);
      if (!var2.a(var11, var6, var1)) {
        return UseResult.CANT_USE;
      } else {
        BlockPosition var12 = var11.up();
        boolean var13 =
            !var3.isEmpty(var11) && !var3.getType(var11).getBlock().isReplaceable(var3, var11);
        var13 |= !var3.isEmpty(var12) && !var3.getType(var12).getBlock().isReplaceable(var3, var12);
        if (var13) {
          return UseResult.CANT_USE;
        } else {
          double var14 = (double) var11.getX();
          double var16 = (double) var11.getY();
          double var18 = (double) var11.getZ();
          List var20 =
              var3.getEntities(
                  (Entity) null,
                  (AxisAlignedBB)
                      AxisAlignedBB.a(
                          var14, var16, var18, var14 + 1.0D, var16 + 2.0D, var18 + 1.0D));
          if (!var20.isEmpty()) {
            return UseResult.CANT_USE;
          } else {
            if (!var3.isClientSide) {
              var3.setAir(var11);
              var3.setAir(var12);
              EntityArmorStand var21 =
                  new EntityArmorStand(var3, var14 + 0.5D, var16, var18 + 0.5D);
              float var22 =
                  (float)
                          MathHelper.floor(
                              (MathHelper.clampAngle(var2.yaw - 180.0F) + 22.5F) / 45.0F)
                      * 45.0F;
              var21.setPositionRotation(var14 + 0.5D, var16, var18 + 0.5D, var22, 0.0F);
              this.a(var21, var3.random);
              NBTTagCompound var23 = var1.getTag();
              if (var23 != null && var23.hasOfType("EntityTag", 10)) {
                NBTTagCompound var24 = new NBTTagCompound();
                var21.d(var24);
                var24.copyFrom(var23.getCompound("EntityTag"));
                var21.f(var24);
              }

              var3.addEntity((Entity) var21);
            }

            --var1.count;
            return UseResult.SUCCESS;
          }
        }
      }
    }
  }
Example #8
0
  public boolean interactWith(
      ItemStack itemstack,
      EntityHuman entityhuman,
      World world,
      int i,
      int j,
      int k,
      int l,
      float f,
      float f1,
      float f2) {
    if (!entityhuman.a(i, j, k, l, itemstack)) {
      return false;
    } else {
      int i1;
      int j1;
      int k1;

      if (itemstack.getData() == 15) {
        i1 = world.getTypeId(i, j, k);
        if (i1 == Block.SAPLING.id) {
          if (!world.isStatic) {
            // CraftBukkit start
            Player player =
                (entityhuman instanceof EntityPlayer)
                    ? (Player) entityhuman.getBukkitEntity()
                    : null;
            ((BlockSapling) Block.SAPLING)
                .grow(world, i, j, k, world.random, true, player, itemstack);
            // --itemstack.count; - called later if the bonemeal attempt was succesful
            // CraftBukkit end
          }

          return true;
        }

        if (i1 == Block.BROWN_MUSHROOM.id || i1 == Block.RED_MUSHROOM.id) {
          // CraftBukkit start
          if (!world.isStatic) {
            Player player =
                (entityhuman instanceof EntityPlayer)
                    ? (Player) entityhuman.getBukkitEntity()
                    : null;
            ((BlockMushroom) Block.byId[i1])
                .grow(world, i, j, k, world.random, true, player, itemstack);
            // --itemstack.count; - called later if the bonemeal attempt was succesful
            // CraftBukkit end
          }

          return true;
        }

        if (i1 == Block.MELON_STEM.id || i1 == Block.PUMPKIN_STEM.id) {
          if (world.getData(i, j, k) == 7) {
            return false;
          }

          if (!world.isStatic) {
            ((BlockStem) Block.byId[i1]).l(world, i, j, k);
            --itemstack.count;
          }

          return true;
        }

        if (i1 > 0 && Block.byId[i1] instanceof BlockCrops) {
          if (world.getData(i, j, k) == 7) {
            return false;
          }

          if (!world.isStatic) {
            ((BlockCrops) Block.byId[i1]).c_(world, i, j, k);
            --itemstack.count;
          }

          return true;
        }

        if (i1 == Block.COCOA.id) {
          if (!world.isStatic) {
            world.setData(i, j, k, 8 | BlockDirectional.e(world.getData(i, j, k)));
            --itemstack.count;
          }

          return true;
        }

        if (i1 == Block.GRASS.id) {
          if (!world.isStatic) {
            --itemstack.count;

            label133:
            for (j1 = 0; j1 < 128; ++j1) {
              k1 = i;
              int l1 = j + 1;
              int i2 = k;

              for (int j2 = 0; j2 < j1 / 16; ++j2) {
                k1 += d.nextInt(3) - 1;
                l1 += (d.nextInt(3) - 1) * d.nextInt(3) / 2;
                i2 += d.nextInt(3) - 1;
                if (world.getTypeId(k1, l1 - 1, i2) != Block.GRASS.id || world.t(k1, l1, i2)) {
                  continue label133;
                }
              }

              if (world.getTypeId(k1, l1, i2) == 0) {
                if (d.nextInt(10) != 0) {
                  if (Block.LONG_GRASS.d(world, k1, l1, i2)) {
                    world.setTypeIdAndData(k1, l1, i2, Block.LONG_GRASS.id, 1);
                  }
                } else if (d.nextInt(3) != 0) {
                  if (Block.YELLOW_FLOWER.d(world, k1, l1, i2)) {
                    world.setTypeId(k1, l1, i2, Block.YELLOW_FLOWER.id);
                  }
                } else if (Block.RED_ROSE.d(world, k1, l1, i2)) {
                  world.setTypeId(k1, l1, i2, Block.RED_ROSE.id);
                }
              }
            }
          }

          return true;
        }
      } else if (itemstack.getData() == 3) {
        i1 = world.getTypeId(i, j, k);
        j1 = world.getData(i, j, k);
        if (i1 == Block.LOG.id && BlockLog.e(j1) == 3) {
          if (l == 0) {
            return false;
          }

          if (l == 1) {
            return false;
          }

          if (l == 2) {
            --k;
          }

          if (l == 3) {
            ++k;
          }

          if (l == 4) {
            --i;
          }

          if (l == 5) {
            ++i;
          }

          if (world.isEmpty(i, j, k)) {
            k1 = Block.byId[Block.COCOA.id].getPlacedData(world, i, j, k, l, f, f1, f2, 0);
            world.setTypeIdAndData(i, j, k, Block.COCOA.id, k1);
            if (!entityhuman.abilities.canInstantlyBuild) {
              --itemstack.count;
            }
          }

          return true;
        }
      }

      return false;
    }
  }
Example #9
0
  public void a(World world, int i, int j, int k, Random random) {
    if (!world.isStatic && world.random.nextInt(16) == 0) {
      byte b0 = 4;
      int l = 5;
      boolean flag = false;

      int i1;
      int j1;
      int k1;

      label138:
      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) {
                flag = true;
                break label138;
              }
            }
          }
        }
      }

      i1 = world.getData(i, j, k);
      j1 = world.random.nextInt(6);
      k1 = Direction.d[j1];
      int l1;
      int i2;

      if (j1 == 1) {
        world.getClass();
        if (j < 128 - 1 && world.isEmpty(i, j + 1, k)) {
          if (flag) {
            return;
          }

          l1 = world.random.nextInt(16) & i1;
          if (l1 > 0) {
            for (i2 = 0; i2 <= 3; ++i2) {
              if (!this.c(world.getTypeId(i + Direction.a[i2], j + 1, k + Direction.b[i2]))) {
                l1 &= ~(1 << i2);
              }
            }

            if (l1 > 0) {
              world.setTypeIdAndData(i, j + 1, k, this.id, l1);
              return;
            }
          }

          return;
        }
      }

      int j2;

      if (j1 >= 2 && j1 <= 5 && (i1 & 1 << k1) == 0) {
        if (flag) {
          return;
        }

        l1 = world.getTypeId(i + Direction.a[k1], j, k + Direction.b[k1]);
        if (l1 != 0 && Block.byId[l1] != null) {
          if (Block.byId[l1].material.j() && Block.byId[l1].b()) {
            world.setData(i, j, k, i1 | 1 << k1);
          }
        } else {
          i2 = k1 + 1 & 3;
          j2 = k1 + 3 & 3;
          if ((i1 & 1 << i2) != 0
              && this.c(
                  world.getTypeId(
                      i + Direction.a[k1] + Direction.a[i2],
                      j,
                      k + Direction.b[k1] + Direction.b[i2]))) {
            world.setTypeIdAndData(i + Direction.a[k1], j, k + Direction.b[k1], this.id, 1 << i2);
          } else if ((i1 & 1 << j2) != 0
              && this.c(
                  world.getTypeId(
                      i + Direction.a[k1] + Direction.a[j2],
                      j,
                      k + Direction.b[k1] + Direction.b[j2]))) {
            world.setTypeIdAndData(i + Direction.a[k1], j, k + Direction.b[k1], this.id, 1 << j2);
          } else if ((i1 & 1 << i2) != 0
              && world.isEmpty(
                  i + Direction.a[k1] + Direction.a[i2], j, k + Direction.b[k1] + Direction.b[i2])
              && this.c(world.getTypeId(i + Direction.a[i2], j, k + Direction.b[i2]))) {
            world.setTypeIdAndData(
                i + Direction.a[k1] + Direction.a[i2],
                j,
                k + Direction.b[k1] + Direction.b[i2],
                this.id,
                1 << (k1 + 2 & 3));
          } else if ((i1 & 1 << j2) != 0
              && world.isEmpty(
                  i + Direction.a[k1] + Direction.a[j2], j, k + Direction.b[k1] + Direction.b[j2])
              && this.c(world.getTypeId(i + Direction.a[j2], j, k + Direction.b[j2]))) {
            world.setTypeIdAndData(
                i + Direction.a[k1] + Direction.a[j2],
                j,
                k + Direction.b[k1] + Direction.b[j2],
                this.id,
                1 << (k1 + 2 & 3));
          } else if (this.c(world.getTypeId(i + Direction.a[k1], j + 1, k + Direction.b[k1]))) {
            world.setTypeIdAndData(i + Direction.a[k1], j, k + Direction.b[k1], this.id, 0);
          }
        }
      } else if (j > 1) {
        l1 = world.getTypeId(i, j - 1, k);
        if (l1 == 0) {
          i2 = world.random.nextInt(16) & i1;
          if (i2 > 0) {
            world.setTypeIdAndData(i, j - 1, k, this.id, i2);
          }
        } else if (l1 == this.id) {
          i2 = world.random.nextInt(16) & i1;
          j2 = world.getData(i, j - 1, k);
          if (j2 != (j2 | i2)) {
            world.setData(i, j - 1, k, j2 | i2);
          }
        }
      }
    }
  }
Example #10
0
  public boolean generate(World world, Random random, int i, int j, int k) {
    while (world.isEmpty(i, j, k) && j > 2) {
      --j;
    }

    if (world.getType(i, j, k) != Blocks.SNOW_BLOCK) {
      return false;
    } else {
      j += random.nextInt(4);
      int l = random.nextInt(4) + 7;
      int i1 = l / 4 + random.nextInt(2);

      if (i1 > 1 && random.nextInt(60) == 0) {
        j += 10 + random.nextInt(30);
      }

      int j1;
      int k1;
      int l1;

      for (j1 = 0; j1 < l; ++j1) {
        float f = (1.0F - (float) j1 / (float) l) * (float) i1;

        k1 = MathHelper.f(f);

        for (l1 = -k1; l1 <= k1; ++l1) {
          float f1 = (float) MathHelper.a(l1) - 0.25F;

          for (int i2 = -k1; i2 <= k1; ++i2) {
            float f2 = (float) MathHelper.a(i2) - 0.25F;

            if ((l1 == 0 && i2 == 0 || f1 * f1 + f2 * f2 <= f * f)
                && (l1 != -k1 && l1 != k1 && i2 != -k1 && i2 != k1
                    || random.nextFloat() <= 0.75F)) {
              Block block = world.getType(i + l1, j + j1, k + i2);

              if (block.getMaterial() == Material.AIR
                  || block == Blocks.DIRT
                  || block == Blocks.SNOW_BLOCK
                  || block == Blocks.ICE) {
                world.setTypeUpdate(i + l1, j + j1, k + i2, Blocks.PACKED_ICE); // Spigot
              }

              if (j1 != 0 && k1 > 1) {
                block = world.getType(i + l1, j - j1, k + i2);
                if (block.getMaterial() == Material.AIR
                    || block == Blocks.DIRT
                    || block == Blocks.SNOW_BLOCK
                    || block == Blocks.ICE) {
                  world.setTypeUpdate(i + l1, j - j1, k + i2, Blocks.PACKED_ICE); // Spigot
                }
              }
            }
          }
        }
      }

      j1 = i1 - 1;
      if (j1 < 0) {
        j1 = 0;
      } else if (j1 > 1) {
        j1 = 1;
      }

      for (int j2 = -j1; j2 <= j1; ++j2) {
        k1 = -j1;

        while (k1 <= j1) {
          l1 = j - 1;
          int k2 = 50;

          if (Math.abs(j2) == 1 && Math.abs(k1) == 1) {
            k2 = random.nextInt(5);
          }

          while (true) {
            if (l1 > 50) {
              Block block1 = world.getType(i + j2, l1, k + k1);

              if (block1.getMaterial() == Material.AIR
                  || block1 == Blocks.DIRT
                  || block1 == Blocks.SNOW_BLOCK
                  || block1 == Blocks.ICE
                  || block1 == Blocks.PACKED_ICE) {
                world.setTypeUpdate(i + j2, l1, k + k1, Blocks.PACKED_ICE); // Spigot
                --l1;
                --k2;
                if (k2 <= 0) {
                  l1 -= random.nextInt(5) + 1;
                  k2 = random.nextInt(5);
                }
                continue;
              }
            }

            ++k1;
            break;
          }
        }
      }

      return true;
    }
  }
  public boolean interactWith(
      ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
    int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit

    if (world.getTypeId(i, j, k) != Block.SNOW.id) {
      if (l == 0) {
        --j;
      }

      if (l == 1) {
        ++j;
      }

      if (l == 2) {
        --k;
      }

      if (l == 3) {
        ++k;
      }

      if (l == 4) {
        --i;
      }

      if (l == 5) {
        ++i;
      }

      if (!world.isEmpty(i, j, k)) {
        return false;
      }
    }

    if (!entityhuman.d(i, j, k)) {
      return false;
    } else {
      if (Block.REDSTONE_WIRE.canPlace(world, i, j, k)) {
        // CraftBukkit start
        CraftBlockState blockState = CraftBlockState.getBlockState(world, i, j, k);

        world.suppressPhysics = true;
        world.setRawTypeId(i, j, k, Block.REDSTONE_WIRE.id); // We update after the event

        org.bukkit.event.block.BlockPlaceEvent event =
            org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(
                world, entityhuman, blockState, clickedX, clickedY, clickedZ);
        blockState.update(true);

        world.suppressPhysics = false;
        if (event.isCancelled() || !event.canBuild()) {
          return false;
        }
        // CraftBukkit end

        --itemstack.count;
        world.setTypeId(i, j, k, Block.REDSTONE_WIRE.id);
      }

      return true;
    }
  }