Example #1
0
  @Override
  public void d(ItemStack itemstack, World world, EntityHuman entityhuman) {
    if (itemstack.hasTag() && itemstack.getTag().getBoolean("map_is_scaling")) {
      WorldMap worldmap = Items.MAP.getSavedMap(itemstack, world);

      world =
          world.getServer().getServer().worlds.get(0); // CraftBukkit - use primary world for maps

      itemstack.setData(world.b("map"));
      WorldMap worldmap1 = new WorldMap("map_" + itemstack.getData());

      worldmap1.scale = (byte) (worldmap.scale + 1);
      if (worldmap1.scale > 4) {
        worldmap1.scale = 4;
      }

      worldmap1.centerX = worldmap.centerX;
      worldmap1.centerZ = worldmap.centerZ;
      worldmap1.map = worldmap.map;
      worldmap1.c();
      world.a("map_" + itemstack.getData(), worldmap1);

      // CraftBukkit start
      MapInitializeEvent event = new MapInitializeEvent(worldmap1.mapView);
      Bukkit.getServer().getPluginManager().callEvent(event);
      // CraftBukkit end
    }
  }
Example #2
0
  public WorldMap getSavedMap(ItemStack itemstack, World world) {
    World worldMain =
        world
            .getServer()
            .getServer()
            .worlds
            .get(0); // CraftBukkit - store reference to primary world
    String s = "map_" + itemstack.getData();
    WorldMap worldmap =
        (WorldMap) worldMain.a(WorldMap.class, s); // CraftBukkit - use primary world for maps

    if (worldmap == null && !world.isStatic) {
      itemstack.setData(worldMain.b("map")); // CraftBukkit - use primary world for maps
      s = "map_" + itemstack.getData();
      worldmap = new WorldMap(s);
      worldmap.scale = 3;
      int i = 128 * (1 << worldmap.scale);

      worldmap.centerX = Math.round((float) world.getWorldData().c() / (float) i) * i;
      worldmap.centerZ = Math.round(world.getWorldData().e() / i) * i;
      worldmap.map =
          (byte) ((WorldServer) world).dimension; // CraftBukkit - fixes Bukkit multiworld maps
      worldmap.c();
      worldMain.a(s, worldmap); // CraftBukkit - use primary world for maps

      // CraftBukkit start
      MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
      Bukkit.getServer().getPluginManager().callEvent(event);
      // CraftBukkit end
    }

    return worldmap;
  }
Example #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
      }
    }
  }
  public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
    EnumFacing enumfacing = BlockDispenser.b(isourceblock.h());
    double d0 = isourceblock.getX() + (double) enumfacing.c();
    double d1 = (double) ((float) isourceblock.getBlockY() + 0.2F);
    double d2 = isourceblock.getZ() + (double) enumfacing.e();

    // CraftBukkit start
    World world = isourceblock.k();
    ItemStack itemstack1 = itemstack.a(1);
    org.bukkit.block.Block block =
        world
            .getWorld()
            .getBlockAt(
                isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ());
    CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);

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

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

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

    itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
    EntityFireworks entityfireworks =
        new EntityFireworks(
            isourceblock.k(),
            event.getVelocity().getX(),
            event.getVelocity().getY(),
            event.getVelocity().getZ(),
            itemstack1);

    isourceblock.k().addEntity(entityfireworks);
    // itemstack.a(1); // Handled during event processing
    // CraftBukkit end

    return itemstack;
  }
Example #5
0
  private void l(World world, int i, int j, int k) {
    // CraftBukkit start
    LeavesDecayEvent event = new LeavesDecayEvent(world.getWorld().getBlockAt(i, j, k));
    world.getServer().getPluginManager().callEvent(event);

    if (event.isCancelled()) {
      return;
    }
    // CraftBukkit end

    this.c(world, i, j, k, world.getData(i, j, k), 0);
    world.setTypeId(i, j, k, 0);
  }
Example #6
0
 public EntityPet(World world, Pet pet) {
   super(world);
   try {
     pet.setCraftPet(new CraftPet(world.getServer(), this));
     // pet.setCraftPet(pet.getPetType().getNewCraftInstance(this));
     // setPet(pet);
     this.pet = pet;
     ((LivingEntity) this.getBukkitEntity()).setMaxHealth(pet.getPetType().getMaxHealth());
     this.setHealth(pet.getPetType().getMaxHealth());
     this.jumpHeight =
         EchoPet.getPluginInstance().DO.getRideJumpHeight(this.getPet().getPetType());
     this.rideSpeed = EchoPet.getPluginInstance().DO.getRideSpeed(this.getPet().getPetType());
     this.jump = EntityLiving.class.getDeclaredField("bd");
     this.jump.setAccessible(true);
     setPathfinding();
   } catch (Exception e) {
     EchoPet.getPluginInstance().severe(e, "Error creating new pet entity.");
     this.remove();
   }
 }
Example #7
0
  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;
  }
  private void k(World world, int i, int j, int k) {
    int l = world.getData(i, j, k);
    boolean flag = (l & 1) == 1;
    boolean flag1 = false;
    List list =
        world.getEntities(
            (Entity) null,
            AxisAlignedBB.a()
                .a(
                    (double) i + this.minX,
                    (double) j + this.minY,
                    (double) k + this.minZ,
                    (double) i + this.maxX,
                    (double) j + this.maxY,
                    (double) k + this.maxZ));

    if (!list.isEmpty()) {
      Iterator iterator = list.iterator();

      while (iterator.hasNext()) {
        Entity entity = (Entity) iterator.next();

        if (!entity.at()) {
          flag1 = true;
          break;
        }
      }
    }

    // CraftBukkit start - Call interact even when triggering connected tripwire
    if (flag != flag1 && flag1 && (world.getData(i, j, k) & 4) == 4) {
      org.bukkit.World bworld = world.getWorld();
      org.bukkit.plugin.PluginManager manager = world.getServer().getPluginManager();
      org.bukkit.block.Block block = bworld.getBlockAt(i, j, k);
      boolean allowed = false;

      // If all of the events are cancelled block the tripwire trigger, else allow
      for (Object object : list) {
        if (object != null) {
          org.bukkit.event.Cancellable cancellable;

          if (object instanceof EntityHuman) {
            cancellable =
                org.bukkit.craftbukkit.event.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(), block);
            manager.callEvent((EntityInteractEvent) cancellable);
          } else {
            continue;
          }

          if (!cancellable.isCancelled()) {
            allowed = true;
            break;
          }
        }
      }

      if (!allowed) {
        return;
      }
    }
    // CraftBukkit end

    if (flag1 && !flag) {
      l |= 1;
    }

    if (!flag1 && flag) {
      l &= -2;
    }

    if (flag1 != flag) {
      world.setData(i, j, k, l, 3);
      this.d(world, i, j, k, l);
    }

    if (flag1) {
      world.a(i, j, k, this.id, this.a(world));
    }
  }
  // CraftBukkit - priv to public
  public void dispense(World world, int i, int j, int k, Random random) {
    int l = world.getData(i, j, k);
    byte b0 = 0;
    byte b1 = 0;

    if (l == 3) {
      b1 = 1;
    } else if (l == 2) {
      b1 = -1;
    } else if (l == 5) {
      b0 = 1;
    } else {
      b0 = -1;
    }

    TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k);

    if (tileentitydispenser != null) {
      // CraftBukkit start
      int dispenseSlot = tileentitydispenser.findDispenseSlot();
      ItemStack itemstack = null;
      if (dispenseSlot > -1) {
        itemstack = tileentitydispenser.getContents()[dispenseSlot];

        // Copy item stack, because we want it to have 1 item
        itemstack =
            new ItemStack(itemstack.id, 1, itemstack.getData(), itemstack.getEnchantments());
      }
      // CraftBukkit end

      double d0 = (double) i + (double) b0 * 0.6D + 0.5D;
      double d1 = (double) j + 0.5D;
      double d2 = (double) k + (double) b1 * 0.6D + 0.5D;

      if (itemstack == null) {
        world.triggerEffect(1001, i, j, k, 0);
      } else {
        // CraftBukkit start
        double d3 = random.nextDouble() * 0.1D + 0.2D;
        double motX = (double) b0 * d3;
        double motY = 0.20000000298023224D;
        double motZ = (double) b1 * d3;
        motX += random.nextGaussian() * 0.007499999832361937D * 6.0D;
        motY += random.nextGaussian() * 0.007499999832361937D * 6.0D;
        motZ += random.nextGaussian() * 0.007499999832361937D * 6.0D;

        org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k);
        org.bukkit.inventory.ItemStack bukkitItem = new CraftItemStack(itemstack).clone();

        BlockDispenseEvent event =
            new BlockDispenseEvent(block, bukkitItem, new Vector(motX, motY, motZ));
        world.getServer().getPluginManager().callEvent(event);

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

        if (event.getItem().equals(bukkitItem)) {
          // Actually remove the item
          tileentitydispenser.splitStack(dispenseSlot, 1);
        }

        motX = event.getVelocity().getX();
        motY = event.getVelocity().getY();
        motZ = event.getVelocity().getZ();

        itemstack = CraftItemStack.createNMSItemStack(event.getItem());
        // CraftBukkit end

        if (itemstack.id == Item.ARROW.id) {
          EntityArrow entityarrow = new EntityArrow(world, d0, d1, d2);

          entityarrow.shoot((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F);
          entityarrow.fromPlayer = true;
          world.addEntity(entityarrow);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.EGG.id) {
          EntityEgg entityegg = new EntityEgg(world, d0, d1, d2);

          entityegg.a((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F);
          world.addEntity(entityegg);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.SNOW_BALL.id) {
          EntitySnowball entitysnowball = new EntitySnowball(world, d0, d1, d2);

          entitysnowball.a((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F);
          world.addEntity(entitysnowball);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.POTION.id && ItemPotion.c(itemstack.getData())) {
          EntityPotion entitypotion = new EntityPotion(world, d0, d1, d2, itemstack.getData());

          entitypotion.a((double) b0, 0.10000000149011612D, (double) b1, 1.375F, 3.0F);
          world.addEntity(entitypotion);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.EXP_BOTTLE.id) {
          EntityThrownExpBottle entitythrownexpbottle =
              new EntityThrownExpBottle(world, d0, d1, d2);

          entitythrownexpbottle.a((double) b0, 0.10000000149011612D, (double) b1, 1.375F, 3.0F);
          world.addEntity(entitythrownexpbottle);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.MONSTER_EGG.id) {
          ItemMonsterEgg.a(
              world,
              itemstack.getData(),
              d0 + (double) b0 * 0.3D,
              d1 - 0.3D,
              d2 + (double) b1 * 0.3D);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.FIREBALL.id) {
          EntitySmallFireball entitysmallfireball =
              new EntitySmallFireball(
                  world,
                  d0 + (double) b0 * 0.3D,
                  d1,
                  d2 + (double) b1 * 0.3D,
                  (double) b0 + random.nextGaussian() * 0.05D,
                  random.nextGaussian() * 0.05D,
                  (double) b1 + random.nextGaussian() * 0.05D);

          world.addEntity(entitysmallfireball);
          world.triggerEffect(1009, i, j, k, 0);
        } else {
          EntityItem entityitem = new EntityItem(world, d0, d1 - 0.3D, d2, itemstack);
          // CraftBukkit start
          // double d3 = random.nextDouble() * 0.1D + 0.2D; // Moved up
          entityitem.motX = motX;
          entityitem.motY = motY;
          entityitem.motZ = motZ;
          // CraftBukkit end
          world.addEntity(entityitem);
          world.triggerEffect(1000, i, j, k, 0);
        }

        world.triggerEffect(2000, i, j, k, b0 + 1 + (b1 + 1) * 3);
      }
    }
  }
Example #10
0
  private void a(World world, int i, int j, int k, int l, int i1, int j1) {
    int k1 = world.getData(i, j, k);
    int l1 = 0;

    this.a = false;
    boolean flag = world.isBlockIndirectlyPowered(i, j, k);

    this.a = true;

    if (flag) {
      l1 = 15;
    } else {
      for (int i2 = 0; i2 < 4; i2++) {
        int j2 = i;
        int k2 = k;
        if (i2 == 0) {
          j2 = i - 1;
        }

        if (i2 == 1) {
          j2++;
        }

        if (i2 == 2) {
          k2 = k - 1;
        }

        if (i2 == 3) {
          k2++;
        }

        if ((j2 != l) || (j != i1) || (k2 != j1)) {
          l1 = getPower(world, j2, j, k2, l1);
        }

        if ((world.s(j2, j, k2)) && (!world.s(i, j + 1, k))) {
          if ((j2 != l) || (j + 1 != i1) || (k2 != j1)) l1 = getPower(world, j2, j + 1, k2, l1);
        } else if ((!world.s(j2, j, k2)) && ((j2 != l) || (j - 1 != i1) || (k2 != j1))) {
          l1 = getPower(world, j2, j - 1, k2, l1);
        }
      }

      if (l1 > 0) l1--;
      else {
        l1 = 0;
      }
    }

    if (k1 != l1) {
      BlockRedstoneEvent event =
          new BlockRedstoneEvent(world.getWorld().getBlockAt(i, j, k), k1, l1);
      world.getServer().getPluginManager().callEvent(event);

      l1 = event.getNewCurrent();
    }

    if (k1 != l1) {
      world.suppressPhysics = true;
      world.setData(i, j, k, l1);
      world.d(i, j, k, i, j, k);
      world.suppressPhysics = false;

      for (int i2 = 0; i2 < 4; i2++) {
        int j2 = i;
        int k2 = k;
        int l2 = j - 1;

        if (i2 == 0) {
          j2 = i - 1;
        }

        if (i2 == 1) {
          j2++;
        }

        if (i2 == 2) {
          k2 = k - 1;
        }

        if (i2 == 3) {
          k2++;
        }

        if (world.s(j2, j, k2)) {
          l2 += 2;
        }

        boolean flag1 = false;
        int i3 = getPower(world, j2, j, k2, -1);

        l1 = world.getData(i, j, k);
        if (l1 > 0) {
          l1--;
        }

        if ((i3 >= 0) && (i3 != l1)) {
          a(world, j2, j, k2, i, j, k);
        }

        i3 = getPower(world, j2, l2, k2, -1);
        l1 = world.getData(i, j, k);
        if (l1 > 0) {
          l1--;
        }

        if ((i3 >= 0) && (i3 != l1)) {
          a(world, j2, l2, k2, i, j, k);
        }
      }

      if ((k1 < l1) || (l1 == 0)) {
        this.b.add(new ChunkPosition(i, j, k));
        this.b.add(new ChunkPosition(i - 1, j, k));
        this.b.add(new ChunkPosition(i + 1, j, k));
        this.b.add(new ChunkPosition(i, j - 1, k));
        this.b.add(new ChunkPosition(i, j + 1, k));
        this.b.add(new ChunkPosition(i, j, k - 1));
        this.b.add(new ChunkPosition(i, j, k + 1));
      }
    }
  }
Example #11
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());
    }
  }
  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 ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
    World world = isourceblock.i();
    IPosition iposition = BlockDispenser.a(isourceblock);
    EnumDirection enumdirection = BlockDispenser.b(isourceblock.f());
    IProjectile iprojectile = this.a(world, iposition);

    // iprojectile.shoot((double) enumdirection.getAdjacentX(), (double) ((float)
    // enumdirection.getAdjacentY() + 0.1F), (double) enumdirection.getAdjacentZ(), this.b(),
    // this.a());
    // CraftBukkit start
    ItemStack itemstack1 = itemstack.a(1);
    org.bukkit.block.Block block =
        world
            .getWorld()
            .getBlockAt(
                isourceblock.getBlockPosition().getX(),
                isourceblock.getBlockPosition().getY(),
                isourceblock.getBlockPosition().getZ());
    CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);

    BlockDispenseEvent event =
        new BlockDispenseEvent(
            block,
            craftItem.clone(),
            new org.bukkit.util.Vector(
                (double) enumdirection.getAdjacentX(),
                (double) ((float) enumdirection.getAdjacentY() + 0.1F),
                (double) enumdirection.getAdjacentZ()));
    if (!BlockDispenser.eventFired) {
      world.getServer().getPluginManager().callEvent(event);
    }

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

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

    iprojectile.shoot(
        event.getVelocity().getX(),
        event.getVelocity().getY(),
        event.getVelocity().getZ(),
        this.b(),
        this.a());
    ((Entity) iprojectile).projectileSource =
        new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource(
            (TileEntityDispenser) isourceblock.getTileEntity());
    // CraftBukkit end
    world.addEntity((Entity) iprojectile);
    // itemstack.a(1); // CraftBukkit - Handled during event processing
    return itemstack;
  }
  private void a(World world, int i, int j, int k, int l, int i1, int j1) {
    int k1 = world.getData(i, j, k);
    int l1 = 0;

    this.a = false;
    boolean flag = world.isBlockIndirectlyPowered(i, j, k);

    this.a = true;
    int i2;
    int j2;
    int k2;

    if (flag) {
      l1 = 15;
    } else {
      for (i2 = 0; i2 < 4; ++i2) {
        j2 = i;
        k2 = k;
        if (i2 == 0) {
          j2 = i - 1;
        }

        if (i2 == 1) {
          ++j2;
        }

        if (i2 == 2) {
          k2 = k - 1;
        }

        if (i2 == 3) {
          ++k2;
        }

        if (j2 != l || j != i1 || k2 != j1) {
          l1 = this.getPower(world, j2, j, k2, l1);
        }

        if (world.t(j2, j, k2) && !world.t(i, j + 1, k)) {
          if (j2 != l || j + 1 != i1 || k2 != j1) {
            l1 = this.getPower(world, j2, j + 1, k2, l1);
          }
        } else if (!world.t(j2, j, k2) && (j2 != l || j - 1 != i1 || k2 != j1)) {
          l1 = this.getPower(world, j2, j - 1, k2, l1);
        }
      }

      if (l1 > 0) {
        --l1;
      } else {
        l1 = 0;
      }
    }

    // CraftBukkit start
    if (k1 != l1) {
      BlockRedstoneEvent event =
          new BlockRedstoneEvent(world.getWorld().getBlockAt(i, j, k), k1, l1);
      world.getServer().getPluginManager().callEvent(event);

      l1 = event.getNewCurrent();
    }
    // CraftBukkit end

    if (k1 != l1) {
      world.suppressPhysics = true;
      world.setData(i, j, k, l1);
      world.e(i, j, k, i, j, k);
      world.suppressPhysics = false;

      for (i2 = 0; i2 < 4; ++i2) {
        j2 = i;
        k2 = k;
        int l2 = j - 1;

        if (i2 == 0) {
          j2 = i - 1;
        }

        if (i2 == 1) {
          ++j2;
        }

        if (i2 == 2) {
          k2 = k - 1;
        }

        if (i2 == 3) {
          ++k2;
        }

        if (world.t(j2, j, k2)) {
          l2 += 2;
        }

        boolean flag1 = false;
        int i3 = this.getPower(world, j2, j, k2, -1);

        l1 = world.getData(i, j, k);
        if (l1 > 0) {
          --l1;
        }

        if (i3 >= 0 && i3 != l1) {
          this.a(world, j2, j, k2, i, j, k);
        }

        i3 = this.getPower(world, j2, l2, k2, -1);
        l1 = world.getData(i, j, k);
        if (l1 > 0) {
          --l1;
        }

        if (i3 >= 0 && i3 != l1) {
          this.a(world, j2, l2, k2, i, j, k);
        }
      }

      if (k1 < l1 || l1 == 0) {
        this.b.add(new ChunkPosition(i, j, k));
        this.b.add(new ChunkPosition(i - 1, j, k));
        this.b.add(new ChunkPosition(i + 1, j, k));
        this.b.add(new ChunkPosition(i, j - 1, k));
        this.b.add(new ChunkPosition(i, j + 1, k));
        this.b.add(new ChunkPosition(i, j, k - 1));
        this.b.add(new ChunkPosition(i, j, k + 1));
      }
    }
  }
Example #15
0
  public void b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
    org.bukkit.World bworld = world.getWorld();
    Server server = world.getServer();
    org.bukkit.block.Block source =
        bworld == null
            ? null
            : bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());

    int i = ((Integer) iblockdata.get(LEVEL)).intValue();
    byte b0 = 1;
    if ((this.material == Material.LAVA) && (!world.worldProvider.n())) {
      b0 = 2;
    }
    int j = a(world);
    if (i > 0) {
      int l = -100;

      this.a = 0;
      EnumDirection enumdirection;
      for (Iterator iterator = EnumDirection.EnumDirectionLimit.HORIZONTAL.iterator();
          iterator.hasNext();
          l = a(world, blockposition.shift(enumdirection), l)) {
        enumdirection = (EnumDirection) iterator.next();
      }
      int i1 = l + b0;
      if ((i1 >= 8) || (l < 0)) {
        i1 = -1;
      }
      if (e(world, blockposition.up()) >= 0) {
        int k = e(world, blockposition.up());
        if (k >= 8) {
          i1 = k;
        } else {
          i1 = k + 8;
        }
      }
      if ((this.a >= 2) && (this.material == Material.WATER)) {
        IBlockData iblockdata1 = world.getType(blockposition.down());
        if (iblockdata1.getBlock().getMaterial().isBuildable()) {
          i1 = 0;
        } else if ((iblockdata1.getBlock().getMaterial() == this.material)
            && (((Integer) iblockdata1.get(LEVEL)).intValue() == 0)) {
          i1 = 0;
        }
      }
      if ((this.material == Material.LAVA)
          && (i < 8)
          && (i1 < 8)
          && (i1 > i)
          && (random.nextInt(4) != 0)) {
        j *= 4;
      }
      if (i1 == i) {
        f(world, blockposition, iblockdata);
      } else {
        i = i1;
        if (i1 < 0) {
          world.setAir(blockposition);
        } else {
          iblockdata = iblockdata.set(LEVEL, Integer.valueOf(i1));
          world.setTypeAndData(blockposition, iblockdata, 2);
          world.a(blockposition, this, j);
          world.applyPhysics(blockposition, this);
        }
      }
    } else {
      f(world, blockposition, iblockdata);
    }
    IBlockData iblockdata2 = world.getType(blockposition.down());
    if (h(world, blockposition.down(), iblockdata2)) {
      BlockFromToEvent event = new BlockFromToEvent(source, BlockFace.DOWN);
      if (server != null) {
        server.getPluginManager().callEvent(event);
      }
      if (!event.isCancelled()) {
        if ((this.material == Material.LAVA)
            && (world.getType(blockposition.down()).getBlock().getMaterial() == Material.WATER)) {
          world.setTypeUpdate(blockposition.down(), Blocks.STONE.getBlockData());
          fizz(world, blockposition.down());
          return;
        }
        if (i >= 8) {
          flow(world, blockposition.down(), iblockdata2, i);
        } else {
          flow(world, blockposition.down(), iblockdata2, i + 8);
        }
      }
    } else if ((i >= 0) && ((i == 0) || (g(world, blockposition.down(), iblockdata2)))) {
      Set set = f(world, blockposition);

      int k = i + b0;
      if (i >= 8) {
        k = 1;
      }
      if (k >= 8) {
        return;
      }
      Iterator iterator1 = set.iterator();
      while (iterator1.hasNext()) {
        EnumDirection enumdirection1 = (EnumDirection) iterator1.next();

        BlockFromToEvent event =
            new BlockFromToEvent(source, CraftBlock.notchToBlockFace(enumdirection1));
        if (server != null) {
          server.getPluginManager().callEvent(event);
        }
        if (!event.isCancelled()) {
          flow(
              world,
              blockposition.shift(enumdirection1),
              world.getType(blockposition.shift(enumdirection1)),
              k);
        }
      }
    }
  }