コード例 #1
0
  public boolean interactWith(
      ItemStack itemstack,
      EntityHuman entityhuman,
      World world,
      BlockPosition blockposition,
      EnumDirection enumdirection,
      float f,
      float f1,
      float f2) {
    if (world.isClientSide) {
      return true;
    } else {
      blockposition = blockposition.shift(enumdirection);
      if (!entityhuman.a(blockposition, enumdirection, itemstack)) {
        return false;
      } else {
        if (world.getType(blockposition).getBlock().getMaterial() == Material.AIR) {
          world.makeSound(
              (double) blockposition.getX() + 0.5D,
              (double) blockposition.getY() + 0.5D,
              (double) blockposition.getZ() + 0.5D,
              "item.fireCharge.use",
              1.0F,
              (ItemFireball.g.nextFloat() - ItemFireball.g.nextFloat()) * 0.2F + 1.0F);
          world.setTypeUpdate(blockposition, Blocks.FIRE.getBlockData());
        }

        if (!entityhuman.abilities.canInstantlyBuild) {
          --itemstack.count;
        }

        return true;
      }
    }
  }
コード例 #2
0
ファイル: ItemHoe.java プロジェクト: fouram/mc-dev
  public boolean a(
      ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
    if (!entityhuman.c(i, j, k)) {
      return false;
    } else {
      int i1 = world.getTypeId(i, j, k);
      int j1 = world.getTypeId(i, j + 1, k);

      if ((l == 0 || j1 != 0 || i1 != Block.GRASS.id) && i1 != Block.DIRT.id) {
        return false;
      } else {
        Block block = Block.SOIL;

        world.makeSound(
            (double) ((float) i + 0.5F),
            (double) ((float) j + 0.5F),
            (double) ((float) k + 0.5F),
            block.stepSound.getName(),
            (block.stepSound.getVolume1() + 1.0F) / 2.0F,
            block.stepSound.getVolume2() * 0.8F);
        if (world.isStatic) {
          return true;
        } else {
          world.setTypeId(i, j, k, block.id);
          itemstack.damage(1, entityhuman);
          return true;
        }
      }
    }
  }
コード例 #3
0
 public void playServerSound(World world) {
   world.makeSound(
       this,
       ((ItemGun) mod_ModernWarfare.itemGunFlamethrower).firingSound,
       ((ItemGun) mod_ModernWarfare.itemGunFlamethrower).soundRangeFactor,
       1.0F / (random.nextFloat() * 0.1F + 0.95F));
 }
コード例 #4
0
ファイル: BlockTNT.java プロジェクト: DaMarine/Alkazia
  public void a(World world, int i, int j, int k, int l, EntityLiving entityliving) {
    if (!world.isStatic) {
      if ((l & 1) == 1) {
        EntityTNTPrimed entitytntprimed =
            new EntityTNTPrimed(world, i + 0.5F, j + 0.5F, k + 0.5F, entityliving);

        world.addEntity(entitytntprimed);
        world.makeSound(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F);
      }
    }
  }
コード例 #5
0
ファイル: ItemSnowball.java プロジェクト: Resistance/mc-dev
  public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) {
    if (!entityhuman.abilities.canInstantlyBuild) {
      --itemstack.count;
    }

    world.makeSound(entityhuman, "random.bow", 0.5F, 0.4F / (c.nextFloat() * 0.4F + 0.8F));
    if (!world.isStatic) {
      world.addEntity(new EntitySnowball(world, entityhuman));
    }

    return itemstack;
  }
コード例 #6
0
  public boolean interactWith(
      ItemStack var1, EntityHuman var2, World var3, int var4, int var5, int var6, int var7) {
    if (EEProxy.isClient(var3)) return false;
    boolean var8 = true;
    if (chargeLevel(var1) > 0) {
      cleanDroplist(var1);
      var2.C_();
      var3.makeSound(var2, "flash", 0.8F, 1.5F);
      for (int var9 = -(chargeLevel(var1) * (var7 != 5 ? (byte) (var7 != 4 ? 1 : 0) : 2));
          var9 <= chargeLevel(var1) * (var7 != 5 ? var7 != 4 ? 1 : 2 : 0);
          var9++) {
        for (int var10 = -(chargeLevel(var1) * (var7 != 1 ? (byte) (var7 != 0 ? 1 : 0) : 2));
            var10 <= chargeLevel(var1) * (var7 != 1 ? var7 != 0 ? 1 : 2 : 0);
            var10++) {
          for (int var11 = -(chargeLevel(var1) * (var7 != 3 ? (byte) (var7 != 2 ? 1 : 0) : 2));
              var11 <= chargeLevel(var1) * (var7 != 3 ? var7 != 2 ? 1 : 2 : 0);
              var11++) {
            int var12 = var4 + var9;
            int var13 = var5 + var10;
            int var14 = var6 + var11;
            int var15 = var3.getTypeId(var12, var13, var14);
            int var16 = var3.getData(var12, var13, var14);
            if (canBreak(var15, var16) && attemptBreak(var2, var12, var13, var14)) {
              if (getFuelRemaining(var1) < 1) {
                ConsumeReagent(var1, var2, var8);
                var8 = false;
              }
              if (getFuelRemaining(var1) > 0) {
                ArrayList var17 =
                    Block.byId[var15].getBlockDropped(var3, var12, var13, var14, var16, 0);
                ItemStack var19;
                for (Iterator var18 = var17.iterator(); var18.hasNext(); addToDroplist(var1, var19))
                  var19 = (ItemStack) var18.next();

                var3.setTypeId(var12, var13, var14, 0);
                if (var3.random.nextInt(8) == 0)
                  var3.a("largesmoke", var12, var13, var14, 0.0D, 0.0D, 0.0D);
                if (var3.random.nextInt(8) == 0)
                  var3.a("explode", var12, var13, var14, 0.0D, 0.0D, 0.0D);
                setShort(var1, "fuelRemaining", getFuelRemaining(var1) - 1);
              }
            }
          }
        }
      }

      ejectDropList(var3, var1, var4, var5, var6);
    }
    return false;
  }
コード例 #7
0
ファイル: ItemBlock.java プロジェクト: CasperGrey/MineCraft
  public boolean interactWith(
      ItemStack itemstack,
      EntityHuman entityhuman,
      World world,
      BlockPosition blockposition,
      EnumDirection enumdirection,
      float f,
      float f1,
      float f2) {
    IBlockData iblockdata = world.getType(blockposition);
    Block block = iblockdata.getBlock();

    if (!block.a(world, blockposition)) {
      blockposition = blockposition.shift(enumdirection);
    }

    if (itemstack.count == 0) {
      return false;
    } else if (!entityhuman.a(blockposition, enumdirection, itemstack)) {
      return false;
    } else if (world.a(this.a, blockposition, false, enumdirection, (Entity) null, itemstack)) {
      int i = this.filterData(itemstack.getData());
      IBlockData iblockdata1 =
          this.a.getPlacedState(world, blockposition, enumdirection, f, f1, f2, i, entityhuman);

      if (world.setTypeAndData(blockposition, iblockdata1, 3)) {
        iblockdata1 = world.getType(blockposition);
        if (iblockdata1.getBlock() == this.a) {
          a(world, entityhuman, blockposition, itemstack);
          this.a.postPlace(world, blockposition, iblockdata1, entityhuman, itemstack);
        }

        world.makeSound(
            (double) ((float) blockposition.getX() + 0.5F),
            (double) ((float) blockposition.getY() + 0.5F),
            (double) ((float) blockposition.getZ() + 0.5F),
            this.a.stepSound.getPlaceSound(),
            (this.a.stepSound.getVolume1() + 1.0F) / 2.0F,
            this.a.stepSound.getVolume2() * 0.8F);
        --itemstack.count;
      }

      return true;
    } else {
      return false;
    }
  }
コード例 #8
0
ファイル: ItemHoe.java プロジェクト: CasperGrey/MineCraft
 protected boolean a(
     ItemStack itemstack,
     EntityHuman entityhuman,
     World world,
     BlockPosition blockposition,
     IBlockData iblockdata) {
   world.makeSound(
       (double) ((float) blockposition.getX() + 0.5F),
       (double) ((float) blockposition.getY() + 0.5F),
       (double) ((float) blockposition.getZ() + 0.5F),
       iblockdata.getBlock().stepSound.getStepSound(),
       (iblockdata.getBlock().stepSound.getVolume1() + 1.0F) / 2.0F,
       iblockdata.getBlock().stepSound.getVolume2() * 0.8F);
   if (world.isClientSide) {
     return true;
   } else {
     world.setTypeUpdate(blockposition, iblockdata);
     itemstack.damage(1, entityhuman);
     return true;
   }
 }
コード例 #9
0
ファイル: BlockLever.java プロジェクト: chums122/Spigot
  public boolean interact(
      World world,
      BlockPosition blockposition,
      IBlockData iblockdata,
      EntityHuman entityhuman,
      EnumDirection enumdirection,
      float f,
      float f1,
      float f2) {
    if (world.isClientSide) {
      return true;
    }
    boolean powered = ((Boolean) iblockdata.get(POWERED)).booleanValue();
    org.bukkit.block.Block block =
        world
            .getWorld()
            .getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
    int old = powered ? 15 : 0;
    int current = !powered ? 15 : 0;

    BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current);
    world.getServer().getPluginManager().callEvent(eventRedstone);
    if ((eventRedstone.getNewCurrent() > 0 ? 1 : 0) != (powered ? 0 : 1)) {
      return true;
    }
    iblockdata = iblockdata.a(POWERED);
    world.setTypeAndData(blockposition, iblockdata, 3);
    world.makeSound(
        blockposition.getX() + 0.5D,
        blockposition.getY() + 0.5D,
        blockposition.getZ() + 0.5D,
        "random.click",
        0.3F,
        ((Boolean) iblockdata.get(POWERED)).booleanValue() ? 0.6F : 0.5F);
    world.applyPhysics(blockposition, this);
    EnumDirection enumdirection1 = ((EnumLeverPosition) iblockdata.get(FACING)).c();

    world.applyPhysics(blockposition.shift(enumdirection1.opposite()), this);
    return true;
  }
コード例 #10
0
ファイル: RangedAttack.java プロジェクト: McUsaVsUrss/MyPet
  public void shootProjectile(EntityLiving target, float damage, Projectiles projectile) {
    World world = target.world;

    if (projectile == Projectiles.Arrow) {
      EntityArrow arrow = new MyPetArrow(world, entityMyPet, target, 1.6F, 1);
      arrow.b(damage);
      arrow.setCritical(false);
      entityMyPet.makeSound(
          "random.bow", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
      world.addEntity(arrow);
    } else if (projectile == Projectiles.Snowball) {
      MyPetSnowball snowball = new MyPetSnowball(world, entityMyPet);
      double distanceX = target.locX - entityMyPet.locX;
      double distanceY = target.locY + target.getHeadHeight() - 1.100000023841858D - snowball.locY;
      double distanceZ = target.locZ - entityMyPet.locZ;
      float distance20percent =
          MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F;
      snowball.setDamage(damage);
      snowball.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
      entityMyPet.makeSound(
          "random.bow", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
      world.addEntity(snowball);
    } else if (projectile == Projectiles.Egg) {
      MyPetEgg egg = new MyPetEgg(world, entityMyPet);
      double distanceX = target.locX - entityMyPet.locX;
      double distanceY = target.locY + target.getHeadHeight() - 1.100000023841858D - egg.locY;
      double distanceZ = target.locZ - entityMyPet.locZ;
      float distance20percent =
          MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F;
      egg.setDamage(damage);
      egg.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
      entityMyPet.makeSound(
          "random.bow", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
      world.addEntity(egg);
    } else if (projectile == Projectiles.LargeFireball) {
      double distanceX = this.target.locX - entityMyPet.locX;
      double distanceY =
          this.target.getBoundingBox().b
              + (double) (this.target.length / 2.0F)
              - (0.5D + entityMyPet.locY + (double) (entityMyPet.length / 2.0F));
      double distanceZ = this.target.locZ - entityMyPet.locZ;
      MyPetLargeFireball largeFireball =
          new MyPetLargeFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
      largeFireball.locY = (entityMyPet.locY + entityMyPet.length / 2.0F + 0.5D);
      largeFireball.setDamage(damage);
      world.addEntity(largeFireball);
      world.makeSound(
          entityMyPet.locX + 0.5D,
          entityMyPet.locY + 0.5D,
          entityMyPet.locZ + 0.5D,
          "mob.ghast.fireball",
          1.0F + entityMyPet.getRandom().nextFloat(),
          entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
    } else if (projectile == Projectiles.SmallFireball) {
      double distanceX = this.target.locX - entityMyPet.locX;
      double distanceY =
          this.target.getBoundingBox().b
              + (this.target.length / 2.0F)
              - (0.5D + entityMyPet.locY + (entityMyPet.length / 2.0F));
      double distanceZ = this.target.locZ - entityMyPet.locZ;
      MyPetSmallFireball smallFireball =
          new MyPetSmallFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
      smallFireball.locY = (entityMyPet.locY + entityMyPet.length / 2.0F + 0.5D);
      smallFireball.setDamage(damage);
      world.addEntity(smallFireball);
      world.makeSound(
          entityMyPet.locX + 0.5D,
          entityMyPet.locY + 0.5D,
          entityMyPet.locZ + 0.5D,
          "mob.ghast.fireball",
          1.0F + entityMyPet.getRandom().nextFloat(),
          entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
    } else if (projectile == Projectiles.WitherSkull) {
      double distanceX = this.target.locX - entityMyPet.locX;
      double distanceY =
          this.target.getBoundingBox().b
              + (double) (this.target.length / 2.0F)
              - (0.5D + entityMyPet.locY + (double) (entityMyPet.length / 2.0F));
      double distanceZ = this.target.locZ - entityMyPet.locZ;
      MyPetWitherSkull witherSkull =
          new MyPetWitherSkull(world, entityMyPet, distanceX, distanceY, distanceZ);
      witherSkull.locY = (entityMyPet.locY + entityMyPet.length / 2.0F + 0.5D);
      witherSkull.setDamage(damage);
      world.addEntity(witherSkull);
      world.makeSound(
          entityMyPet.locX + 0.5D,
          entityMyPet.locY + 0.5D,
          entityMyPet.locZ + 0.5D,
          "mob.wither.shoot",
          1.0F + entityMyPet.getRandom().nextFloat(),
          entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
    }
  }
コード例 #11
0
  /**
   * called when the player releases the use item button. Args: itemstack, world, entityplayer,
   * itemInUseCount
   */
  public void a(ItemStack var1, World var2, EntityHuman var3, int var4) {
    // Forge start
    int var5 = this.a(var1) - var4;
    ArrowLooseEvent var6 = new ArrowLooseEvent(var3, var1, var5);
    MinecraftForge.EVENT_BUS.post(var6);

    if (var6.isCanceled()) {
      return;
    }
    var5 = var6.charge;
    // Forge end
    boolean var7 =
        var3.abilities.canInstantlyBuild
            || EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_INFINITE.id, var1) > 0;

    if (var7 || var3.inventory.e(Item.ARROW.id)) {
      float var8 = (float) var5 / 20.0F;
      var8 = (var8 * var8 + var8 * 2.0F) / 3.0F;

      if ((double) var8 < 0.1D) {
        return;
      }

      if (var8 > 1.0F) {
        var8 = 1.0F;
      }

      EntityArrow var9 = new EntityArrow(var2, var3, var8 * 2.0F);

      if (var8 == 1.0F) {
        var9.e(true);
      }

      int var10 = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, var1);

      if (var10 > 0) {
        var9.b(var9.c() + (double) var10 * 0.5D + 0.5D);
      }

      int var11 = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, var1);

      if (var11 > 0) {
        var9.a(var11);
      }

      if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, var1) > 0) {
        var9.setOnFire(100);
      }

      // CraftBukkit start
      org.bukkit.event.entity.EntityShootBowEvent event =
          org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(
              var3, var1, var9, var8);
      if (event.isCancelled()) {
        event.getProjectile().remove();
        return;
      }

      if (event.getProjectile() == var9.getBukkitEntity()) {
        var2.addEntity(var9);
      }
      // CraftBukkit end

      var1.damage(1, var3);
      var2.makeSound(var3, "random.bow", 1.0F, 1.0F / (d.nextFloat() * 0.4F + 1.2F) + var8 * 0.5F);

      if (var7) {
        var9.fromPlayer = 2;
      } else {
        var3.inventory.d(Item.ARROW.id);
      }
    }
  }
コード例 #12
0
ファイル: ItemBlock.java プロジェクト: DaMarine/Alkazia
  // CraftBukkit start - Add method to process block placement
  static boolean processBlockPlace(
      final World world,
      final EntityHuman entityhuman,
      final ItemStack itemstack,
      final int x,
      final int y,
      final int z,
      final Block id,
      final int data,
      final int clickedX,
      final int clickedY,
      final int clickedZ) {
    org.bukkit.block.BlockState blockstate =
        org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(world, x, y, z);

    world.callingPlaceEvent = true;
    // Sign is now 3 not 2.
    int flag = (id == Blocks.SIGN_POST || id == Blocks.WALL_SIGN) ? 3 : 2;
    world.setTypeAndData(x, y, z, id, data, flag);

    org.bukkit.event.block.BlockPlaceEvent event =
        org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(
            world, entityhuman, blockstate, clickedX, clickedY, clickedZ);
    if (event.isCancelled() || !event.canBuild()) {
      blockstate.update(true, false);
      world.callingPlaceEvent = false;
      return false;
    }

    world.callingPlaceEvent = false;

    Block block = world.getType(x, y, z);
    int newData = world.getData(x, y, z);

    if (block != null
        && !(block instanceof BlockContainer)) { // Containers get placed automatically
      block.onPlace(world, x, y, z);
    }

    world.update(x, y, z, block);

    // Cocoa beans placed via ItemDye do not need the rest of the processing
    if (block == Blocks.COCOA && itemstack != null && itemstack.getItem() instanceof ItemDye) {
      return true;
    }

    // Skulls don't get block data applied to them
    if (block != null && block != Blocks.SKULL) {
      block.postPlace(world, x, y, z, entityhuman, itemstack);
      block.postPlace(world, x, y, z, newData);

      world.makeSound(
          (double) ((float) x + 0.5F),
          (double) ((float) y + 0.5F),
          (double) ((float) z + 0.5F),
          block.stepSound.getPlaceSound(),
          (block.stepSound.getVolume1() + 1.0F) / 2.0F,
          block.stepSound.getVolume2() * 0.8F);
    }

    if (itemstack != null) {
      --itemstack.count;
    }

    return true;
  }
コード例 #13
0
  private void g(World world, int i, int j, int k) {
    boolean flag = world.getData(i, j, k) == 1;
    boolean flag1 = false;
    float f = 0.125F;
    List list = null;

    if (this.a == EnumMobType.EVERYTHING) {
      list =
          world.b(
              (Entity) null,
              AxisAlignedBB.b(
                  (double) ((float) i + f),
                  (double) j,
                  (double) ((float) k + f),
                  (double) ((float) (i + 1) - f),
                  (double) j + 0.25D,
                  (double) ((float) (k + 1) - f)));
    }

    if (this.a == EnumMobType.MOBS) {
      list =
          world.a(
              EntityLiving.class,
              AxisAlignedBB.b(
                  (double) ((float) i + f),
                  (double) j,
                  (double) ((float) k + f),
                  (double) ((float) (i + 1) - f),
                  (double) j + 0.25D,
                  (double) ((float) (k + 1) - f)));
    }

    if (this.a == EnumMobType.PLAYERS) {
      list =
          world.a(
              EntityHuman.class,
              AxisAlignedBB.b(
                  (double) ((float) i + f),
                  (double) j,
                  (double) ((float) k + f),
                  (double) ((float) (i + 1) - f),
                  (double) j + 0.25D,
                  (double) ((float) (k + 1) - f)));
    }

    if (list.size() > 0) {
      flag1 = true;
    }

    // CraftBukkit start - Interact Pressure Plate
    org.bukkit.World bworld = world.getWorld();
    org.bukkit.plugin.PluginManager manager = world.getServer().getPluginManager();

    if (flag != flag1) {
      if (flag1) {
        for (Object object : list) {
          if (object != null) {
            org.bukkit.event.Cancellable cancellable;

            if (object instanceof EntityHuman) {
              cancellable =
                  CraftEventFactory.callPlayerInteractEvent(
                      (EntityHuman) object,
                      org.bukkit.event.block.Action.PHYSICAL,
                      i,
                      j,
                      k,
                      -1,
                      null);
            } else if (object instanceof Entity) {
              cancellable =
                  new EntityInteractEvent(
                      ((Entity) object).getBukkitEntity(), bworld.getBlockAt(i, j, k));
              manager.callEvent((EntityInteractEvent) cancellable);
            } else {
              continue;
            }
            if (cancellable.isCancelled()) {
              return;
            }
          }
        }
      }

      BlockRedstoneEvent eventRedstone =
          new BlockRedstoneEvent(bworld.getBlockAt(i, j, k), flag ? 1 : 0, flag1 ? 1 : 0);
      manager.callEvent(eventRedstone);

      flag1 = eventRedstone.getNewCurrent() > 0;
    }
    // CraftBukkit end

    if (flag1 && !flag) {
      world.setData(i, j, k, 1);
      world.applyPhysics(i, j, k, this.id);
      world.applyPhysics(i, j - 1, k, this.id);
      world.b(i, j, k, i, j, k);
      world.makeSound(
          (double) i + 0.5D, (double) j + 0.1D, (double) k + 0.5D, "random.click", 0.3F, 0.6F);
    }

    if (!flag1 && flag) {
      world.setData(i, j, k, 0);
      world.applyPhysics(i, j, k, this.id);
      world.applyPhysics(i, j - 1, k, this.id);
      world.b(i, j, k, i, j, k);
      world.makeSound(
          (double) i + 0.5D, (double) j + 0.1D, (double) k + 0.5D, "random.click", 0.3F, 0.5F);
    }

    if (flag1) {
      world.c(i, j, k, this.id, this.d());
    }
  }
コード例 #14
0
  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
    int i1 = world.getTypeId(i, j, k);

    if (i1 == Block.SNOW.id) {
      l = 1;
    } else if (i1 != Block.VINE.id && i1 != Block.LONG_GRASS.id && i1 != Block.DEAD_BUSH.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 (!entityhuman.d(i, j, k)) {
      return false;
    } else if (itemstack.count == 0) {
      return false;
    } else {
      if (world.mayPlace(this.id, i, j, k, false, l)) {
        Block block = Block.byId[this.id];

        // CraftBukkit start - This executes the placement of the block
        CraftBlockState replacedBlockState =
            CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
        /**
         * @see net.minecraft.server.World#setTypeId(int i, int j, int k, int l)
         *     <p>This replaces world.setTypeId(IIII), we're doing this because we need to hook
         *     between the 'placement' and the informing to 'world' so we can sanely undo this.
         *     <p>Whenever the call to 'world.setTypeId' changes we need to figure out again what to
         *     replace this with.
         */
        if (world.setRawTypeId(i, j, k, this.id)) { // <-- world.e does this to place the block
          org.bukkit.event.block.BlockPlaceEvent event =
              org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(
                  world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ);

          if (event.isCancelled() || !event.canBuild()) {
            // CraftBukkit - undo; this only has reed, repeater and pie blocks
            world.setTypeIdAndData(
                i, j, k, replacedBlockState.getTypeId(), replacedBlockState.getRawData());

            return true;
          }

          world.update(
              i, j, k, this.id); // <-- world.setTypeId does this on success (tell the world)
          // CraftBukkit end

          if (world.getTypeId(i, j, k) == this.id) {
            Block.byId[this.id].postPlace(world, i, j, k, l);
            Block.byId[this.id].postPlace(world, i, j, k, entityhuman);
          }

          world.makeSound(
              (double) ((float) i + 0.5F),
              (double) ((float) j + 0.5F),
              (double) ((float) k + 0.5F),
              block.stepSound.getName(),
              (block.stepSound.getVolume1() + 1.0F) / 2.0F,
              block.stepSound.getVolume2() * 0.8F);
          --itemstack.count;
        }
      }

      return true;
    }
  }
コード例 #15
0
ファイル: ItemBowBauxite.java プロジェクト: DaMarine/Alkazia
  public void a(ItemStack itemstack, World world, EntityHuman entityhuman, int i) {
    boolean flag =
        entityhuman.abilities.canInstantlyBuild
            || EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_INFINITE.id, itemstack) > 0;

    if (flag || entityhuman.inventory.b(Items.ARROW)) {
      int j = this.d(itemstack) - i;
      float f = (float) j / 20.0F;

      f = (f * f + f * 2.0F) / 3.0F;
      if ((double) f < 0.1D) {
        return;
      }

      if (f > 1.0F) {
        f = 1.0F;
      }

      EntityArrow entityarrow = new EntityArrow(world, entityhuman, f * 2.0F);
      entityarrow.damage = 2.3D;

      if (f == 1.0F) {
        entityarrow.setCritical(true);
      }

      int k = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, itemstack);

      if (k > 0) {
        entityarrow.b(entityarrow.j() + (double) k * 0.5D + 0.5D);
      }

      int l = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, itemstack);

      if (l > 0) {
        entityarrow.a(l);
      }

      if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, itemstack) > 0) {
        EntityCombustEvent event = new EntityCombustEvent(entityarrow.getBukkitEntity(), 100);
        entityarrow.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
          entityarrow.setOnFire(event.getDuration());
        }
      }

      // CraftBukkit start
      EntityShootBowEvent event =
          CraftEventFactory.callEntityShootBowEvent(entityhuman, itemstack, entityarrow, f);
      if (event.isCancelled()) {
        event.getProjectile().remove();
        return;
      }

      if (event.getProjectile() == entityarrow.getBukkitEntity()) {
        world.addEntity(entityarrow);
      }
      // CraftBukkit end

      itemstack.damage(1, entityhuman);

      world.makeSound(
          entityhuman, "random.bow", 1.0F, 1.0F / (g.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
      if (flag) {
        entityarrow.fromPlayer = 2;
      } else {
        entityhuman.inventory.a(Items.ARROW);
      }

      entityhuman.b(StatisticList.USE_ITEM_COUNT[Item.getId(this)]);
    }
  }