public ItemStack b(IBlockSource iblocksource, ItemStack itemstack) {
    EnumFacing enumfacing = BlockDispenser.j_(iblocksource.h());
    World world = iblocksource.k();
    double d0 = iblocksource.a() + (double) ((float) enumfacing.c() * 1.125F);
    double d1 = iblocksource.b() + (double) ((float) enumfacing.d() * 1.125F);
    double d2 = iblocksource.c() + (double) ((float) enumfacing.e() * 1.125F);
    int i0 = iblocksource.d() + enumfacing.c();
    int i1 = iblocksource.e() + enumfacing.d();
    int i2 = iblocksource.f() + enumfacing.e();
    int i3 = world.a(i0, i1, i2);
    double d3;

    if (BlockRailBase.d_(i3)) {
      d3 = 0.0D;
    } else {
      if (i3 != 0 || !BlockRailBase.d_(world.a(i0, i1 - 1, i2))) {
        return this.b.a(iblocksource, itemstack);
      }

      d3 = -1.0D;
    }

    EntityMinecart entityminecart =
        EntityMinecart.a(world, d0, d1 + d3, d2, ((ItemMinecart) itemstack.b()).a);

    // CanaryMod: Dispense
    DispenseHook hook =
        new DispenseHook(
            ((TileEntityDispenser) iblocksource.j()).getCanaryDispenser(),
            entityminecart.getCanaryEntity());

    Canary.hooks().callHook(hook);
    if (!hook.isCanceled()) {
      world.d((Entity) entityminecart);
      itemstack.a(1);
    }
    //
    return itemstack;
  }
Exemplo n.º 2
0
  public void a(Packet15Place packet15place) {
    WorldServer worldserver = this.minecraftServer.a(this.player.dimension);

    // CraftBukkit start
    if (this.player.dead) {
      return;
    }

    // This is b horrible hack needed because the client sends 2 packets on 'right mouse click'
    // aimed at b block. We shouldn't need to get the second packet if the data is handled
    // but we cannot know what the client will do, so we might still get it
    //
    // If the time between packets is small enough, and the 'signature' similar, we discard the
    // second one. This sadly has to remain until Mojang makes their packets saner. :(
    //  -- Grum

    if (packet15place.face == 255) {
      if (packet15place.itemstack != null
          && packet15place.itemstack.id == lastMaterial
          && lastPacket != null
          && packet15place.timestamp - lastPacket < 100) {
        lastPacket = null;
        return;
      }
    } else {
      lastMaterial = packet15place.itemstack == null ? -1 : packet15place.itemstack.id;
      lastPacket = packet15place.timestamp;
    }

    // CraftBukkit - if rightclick decremented the item, always send the update packet.
    // this is not here for CraftBukkit's own functionality; rather it is to fix
    // b notch bug where the item doesn't update correctly.
    boolean always = false;

    // CraftBukkit end

    ItemStack itemstack = this.player.inventory.getItemInHand();
    boolean flag =
        worldserver.weirdIsOpCache =
            worldserver.worldProvider.dimension != 0
                || this.minecraftServer.serverConfigurationManager.isOp(this.player.name);

    if (packet15place.face == 255) {
      if (itemstack == null) {
        return;
      }

      // CraftBukkit start
      int itemstackAmount = itemstack.count;
      PlayerInteractEvent event =
          CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack);
      if (event.useItemInHand() != Event.Result.DENY) {
        this.player.itemInWorldManager.useItem(this.player, this.player.world, itemstack);
      }

      // CraftBukkit - notch decrements the counter by 1 in the above method with food,
      // snowballs and so forth, but he does it in b place that doesn't cause the
      // inventory update packet to get sent
      always = (itemstack.count != itemstackAmount);
      // CraftBukkit end
    } else {
      int i = packet15place.a;
      int j = packet15place.b;
      int k = packet15place.c;
      int l = packet15place.face;
      ChunkCoordinates chunkcoordinates = worldserver.getSpawn();
      int i1 = (int) MathHelper.abs((float) (i - chunkcoordinates.x));
      int j1 = (int) MathHelper.abs((float) (k - chunkcoordinates.z));

      if (i1 > j1) {
        j1 = i1;
      }

      // CraftBukkit start - Check if we can actually do something over this large a distance
      Location eyeLoc = getPlayer().getEyeLocation();
      if (Math.pow(eyeLoc.getX() - i, 2)
              + Math.pow(eyeLoc.getY() - j, 2)
              + Math.pow(eyeLoc.getZ() - k, 2)
          > PLACE_DISTANCE_SQUARED) {
        return;
      }
      flag = true; // spawn protection moved to ItemBlock!!!
      // CraftBukkit end

      if (j1 > 16 || flag) {
        this.player.itemInWorldManager.interact(this.player, worldserver, itemstack, i, j, k, l);
      }

      this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
      if (l == 0) {
        --j;
      }

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

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

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

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

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

      this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
    }

    itemstack = this.player.inventory.getItemInHand();
    if (itemstack != null && itemstack.count == 0) {
      this.player.inventory.items[this.player.inventory.itemInHandIndex] = null;
    }

    this.player.h = true;
    this.player.inventory.items[this.player.inventory.itemInHandIndex] =
        ItemStack.b(this.player.inventory.items[this.player.inventory.itemInHandIndex]);
    Slot slot =
        this.player.activeContainer.a(this.player.inventory, this.player.inventory.itemInHandIndex);

    this.player.activeContainer.a();
    this.player.h = false;
    // CraftBukkit
    if (!ItemStack.equals(this.player.inventory.getItemInHand(), packet15place.itemstack)
        || always) {
      this.sendPacket(
          new Packet103SetSlot(
              this.player.activeContainer.f, slot.a, this.player.inventory.getItemInHand()));
    }

    worldserver.weirdIsOpCache = false;
  }
Exemplo n.º 3
0
  @Override
  public void a(Packet102WindowClick packet) {
    if (this.player.dead) return;

    if (this.player.activeContainer.windowId == packet.a
        && this.player.activeContainer.c(this.player)) {
      Inventory inventory = getActiveInventory();
      CraftPlayer player = (CraftPlayer) this.player.getBukkitEntity();
      ItemStack before = ItemStack.b(packet.e);
      ItemStack cursorBefore = this.player.inventory.l();
      SpoutCraftItemStack slot = SpoutCraftItemStack.fromItemStack(before);
      SpoutCraftItemStack cursor = SpoutCraftItemStack.fromItemStack(cursorBefore);
      InventorySlotType type = getActiveInventorySlotType(packet.b);
      boolean clickSuccessful = true;
      final int windowId = packet.a;

      // alert of a newly opened inventory
      if (!activeInventory) {
        activeInventory = true;
        InventoryOpenEvent event =
            new InventoryOpenEvent(player, inventory, getDefaultInventory(), activeLocation);
        Bukkit.getServer().getPluginManager().callEvent(event);
        if (event.isCancelled()) {
          this.player.D();
          activeInventory = false;
          activeLocation = null;
          return;
        }
      }

      // Fire InventoryChange or InventoryCraft event
      if (packet.b != -999) {
        if (inventory instanceof CraftingInventory) {
          CraftingInventory crafting = (CraftingInventory) inventory;
          InventoryCrafting recipe = null;
          if (inventory instanceof SpoutCraftingInventory) {
            recipe = ((SpoutCraftingInventory) crafting).getMatrixHandle();
          } else {
            recipe = (InventoryCrafting) ((SpoutCraftInventoryPlayer) crafting).getMatrixHandle();
          }

          SpoutCraftItemStack craftResult =
              SpoutCraftItemStack.fromItemStack(CraftingManager.getInstance().craft(recipe));
          SpoutCraftItemStack[] recipeContents = new SpoutCraftItemStack[recipe.getSize()];
          for (int i = 0; i < recipe.getSize(); i++) {
            org.bukkit.inventory.ItemStack temp = crafting.getMatrix()[i];
            recipeContents[i] = SpoutCraftItemStack.getCraftItemStack(temp);
          }

          SpoutCraftItemStack[][] matrix = null;
          if (recipe.getSize() == 4) {
            matrix =
                new SpoutCraftItemStack[][] {
                  Arrays.copyOfRange(recipeContents, 0, 2), Arrays.copyOfRange(recipeContents, 2, 4)
                };
          } else if (recipe.getSize() == 9) {
            matrix =
                new SpoutCraftItemStack[][] {
                  Arrays.copyOfRange(recipeContents, 0, 3),
                  Arrays.copyOfRange(recipeContents, 3, 6),
                  Arrays.copyOfRange(recipeContents, 6, 9)
                };
          }
          // Clicking to grab the crafting result
          if (type == InventorySlotType.RESULT) {
            InventoryCraftEvent craftEvent =
                new InventoryCraftEvent(
                    this.getPlayer(),
                    crafting,
                    this.activeLocation,
                    type,
                    packet.b,
                    matrix,
                    craftResult,
                    cursor,
                    packet.c == 0,
                    packet.f);
            Bukkit.getServer().getPluginManager().callEvent(craftEvent);
            craftEvent.getInventory().setResult(craftEvent.getResult());
            cursor = SpoutCraftItemStack.getCraftItemStack(craftEvent.getCursor());
            if (craftEvent.isCancelled()) {
              craftEvent.getInventory().setMatrix(recipeContents);
              setCursorSlot(cursor != null ? cursor.getHandle() : null);
              clickSuccessful = false;
            }
          }
        }
      }

      if (clickSuccessful) {
        clickSuccessful = handleInventoryClick(packet, type, slot, cursor, inventory);
      }

      if (clickSuccessful) {
        this.player.netServerHandler.sendPacket(new Packet106Transaction(windowId, packet.d, true));
        this.player.h = true;
        this.player.activeContainer.a();
        this.player.D();
        this.player.h = false;
      } else {
        this.getEntityList()
            .a(Integer.valueOf(this.player.activeContainer.windowId), Short.valueOf(packet.d));
        this.player.netServerHandler.sendPacket(
            new Packet106Transaction(windowId, packet.d, false));
        this.player.activeContainer.a(this.player, false);
        ArrayList<ItemStack> arraylist = new ArrayList<ItemStack>();

        for (int i = 0; i < this.player.activeContainer.e.size(); ++i) {
          arraylist.add(((Slot) this.player.activeContainer.e.get(i)).getItem());
        }

        this.player.a(this.player.activeContainer, arraylist);
      }
    }
  }
Exemplo n.º 4
0
 public void a(ItemStack itemstack, int i0) {
   super.a(itemstack, i0);
   if (itemstack != null && itemstack.b() != null && itemstack.b().b_(itemstack) == EnumAction.b) {
     this.o().q().b(this, new Packet18Animation(this, 5));
   }
 }