@Override
  public int execute(
      EAI_Manager manager, EntityLiving entity, IInventory inventory, int slotnum, int maxcol) {
    super.execute(manager, entity, inventory, slotnum, maxcol);

    // 食べ物を持ってたら食べる。次へ進む
    //
    // ロジックをなるだけ壊さないように、検索は後ろから
    for (int i = inventory.getSizeInventory() - 1; i > 0; i--) {
      ItemStack stack = inventory.getStackInSlot(i);
      if (stack != null && stack.getItem() instanceof ItemFood) {
        UtilInventory.decrStackSize(inventory, i, 1); // アイテムを 1 つ減らす
        ItemFood food = (ItemFood) stack.getItem();

        entity.worldObj.playSoundEffect(
            entity.posX,
            entity.posY,
            entity.posZ,
            "random.eat",
            0.5F,
            entity.worldObj.rand.nextFloat() * 0.1F + 0.9F);

        entity.setEating(true);
        entity.setEntityHealth(entity.getHealth() + 1); // HP を 1 回復する
        EasyAIInterface.debugPrint("[EAI_TASK_eatFood] Eat Food " + stack + " " + slotnum);

        return this.returnTrue();
      }
    }
    return this.returnFalse();
  }
Пример #2
0
  @Override
  public void doAction(IInventory matrix, DaemonEnergy energy) {
    int size = DaemonMatrix.MATRIX_SIZE;
    int orb = -1;
    ItemOrb orbItem = null;
    int lastSlot = 0;

    // find 1st orb
    for (; lastSlot < size; lastSlot++) {
      ItemStack stack = matrix.getStackInSlot(lastSlot);
      if (stack != null && stack.getItem() instanceof ItemOrb) {
        orb = lastSlot;
        orbItem = (ItemOrb) stack.getItem();
        break;
      }
    }
    if (orb < 0) return;

    // charge with glass shard if possible
    for (int i = 0; i < size; i++) {
      ItemStack stack = matrix.getStackInSlot(i);
      if (stack != null
          && stack.getItem() instanceof ItemShardGlass
          && stack.getItemDamage() >= ItemShardGlass.DAMAGE_CHARGED) {
        matrix.setInventorySlotContents(i, null);
        orbItem.chargeOrb(matrix.getStackInSlot(orb));
        return;
      }
    }

    // charge with crystal
    for (int i = 0; i < size; i++) {
      ItemStack stack = matrix.getStackInSlot(i);
      if (stack != null && stack.getItem() instanceof ItemCrystal) {
        matrix.setInventorySlotContents(i, null);
        DaemonEnergy de = UtilItem.getDaemonEnergy(matrix.getStackInSlot(orb));
        DaemonEnergy de2 = UtilItem.getDaemonEnergy(stack);
        de.merge(de2);
        UtilItem.setDaemonEnergy(matrix.getStackInSlot(orb), de);
        return;
      }
    }

    for (lastSlot++; lastSlot < size; lastSlot++) {
      ItemStack stack = matrix.getStackInSlot(lastSlot);
      if (stack != null && stack.getItem() instanceof ItemOrb) {
        matrix.setInventorySlotContents(orb, orbItem.mergeOrbs(matrix.getStackInSlot(orb), stack));
        matrix.setInventorySlotContents(lastSlot, null);
        return;
      }
    }
  }
Пример #3
0
  public ItemStack checkExtractGeneric(
      IInventory inventory, boolean doRemove, Orientations from, int start, int stop) {
    for (int k = start; k <= stop; ++k)
      if (inventory.getStackInSlot(k) != null && inventory.getStackInSlot(k).stackSize > 0) {

        ItemStack slot = inventory.getStackInSlot(k);

        if (slot != null)
          if (slot.stackSize > 0 && doRemove)
            return inventory.decrStackSize(
                k, (int) powerProvider.useEnergy(1, slot.stackSize, true));
          else if (slot.stackSize < 0) {
            ItemStack k = slot.copy();
            k.stackSize = 1;
            return k;
          } else if (!doRemove) return slot;
      }

    return null;
  }
Пример #4
0
  @Override
  public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
    InventoryEnderChest enderChest = player.getInventoryEnderChest();
    IInventory inventory = enderChest;

    ItemStack extension = inventory.getStackInSlot(0);
    if (extension != null && extension.itemID == ModDaemon.instance.enderExtension.shiftedIndex) {
      UtilItem.setUniqueItem(extension, player);
      IInventory containedInventory =
          UtilItem.getInventory(player, extension, enderChest, enderChest.getSizeInventory());
      inventory = new InventoryMerged(inventory, containedInventory);
    }

    if (inventory != null && ModDaemon.proxy.isSimulating()) {
      enderChest.setAssociatedChest(new TileDaemonEnderChest());
      player.displayGUIChest(inventory);
    }
    return itemStack;
  }
Пример #5
0
  private void dropItems(World world, int x, int y, int z) {
    Random rand = new Random();

    TileEntity tile_entity = world.getBlockTileEntity(x, y, z);

    if (!(tile_entity instanceof IInventory)) {
      return;
    }

    IInventory inventory = (IInventory) tile_entity;

    for (int i = 0; i < inventory.getSizeInventory(); i++) {
      ItemStack item = inventory.getStackInSlot(i);

      if (item != null && item.stackSize > 0) {
        float rx = rand.nextFloat() * 0.6F + 0.1F;
        float ry = rand.nextFloat() * 0.6F + 0.1F;
        float rz = rand.nextFloat() * 0.6F + 0.1F;

        EntityItem entity_item =
            new EntityItem(
                world,
                x + rx,
                y + ry,
                z + rz,
                new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));

        if (item.hasTagCompound()) {
          entity_item.item.setTagCompound((NBTTagCompound) item.getTagCompound().copy());
        }

        float factor = 0.5F;

        entity_item.motionX = rand.nextGaussian() * factor;
        entity_item.motionY = rand.nextGaussian() * factor + 0.2F;
        entity_item.motionZ = rand.nextGaussian() * factor;
        world.spawnEntityInWorld(entity_item);
        item.stackSize = 0;
      }
    }
  }
Пример #6
0
  /**
   * Return the itemstack that can be if something can be extracted from this inventory, null if
   * none. On certain cases, the extractable slot depends on the position of the pipe.
   */
  public ItemStack[] checkExtract(IInventory inventory, boolean doRemove, Orientations from) {

    /// ISPECIALINVENTORY
    if (inventory instanceof ISpecialInventory)
      return ((ISpecialInventory) inventory).extractItem(doRemove, from, 1);

    if (inventory instanceof ISidedInventory) {
      ISidedInventory sidedInv = (ISidedInventory) inventory;

      int first = sidedInv.getStartInventorySide(from.toDirection());
      int last = first + sidedInv.getSizeInventorySide(from.toDirection()) - 1;

      IInventory inv = Utils.getInventory(inventory);

      ItemStack result = checkExtractGeneric(inv, doRemove, from, first, last);

      if (result != null) return new ItemStack[] {result};
    } else if (inventory.getSizeInventory() == 2) {
      // This is an input-output inventory

      int slotIndex = 0;

      if (from == Orientations.YNeg || from == Orientations.YPos) slotIndex = 0;
      else slotIndex = 1;

      ItemStack slot = inventory.getStackInSlot(slotIndex);

      if (slot != null && slot.stackSize > 0)
        if (doRemove)
          return new ItemStack[] {
            inventory.decrStackSize(
                slotIndex, (int) powerProvider.useEnergy(1, slot.stackSize, true))
          };
        else return new ItemStack[] {slot};
    } else if (inventory.getSizeInventory() == 3) {
      // This is a furnace-like inventory

      int slotIndex = 0;

      if (from == Orientations.YPos) slotIndex = 0;
      else if (from == Orientations.YNeg) slotIndex = 1;
      else slotIndex = 2;

      ItemStack slot = inventory.getStackInSlot(slotIndex);

      if (slot != null && slot.stackSize > 0)
        if (doRemove)
          return new ItemStack[] {
            inventory.decrStackSize(
                slotIndex, (int) powerProvider.useEnergy(1, slot.stackSize, true))
          };
        else return new ItemStack[] {slot};
    } else {
      // This is a generic inventory
      IInventory inv = Utils.getInventory(inventory);

      ItemStack result = checkExtractGeneric(inv, doRemove, from, 0, inv.getSizeInventory() - 1);

      if (result != null) return new ItemStack[] {result};
    }

    return null;
  }