protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
   EnumFacing var3 = BlockDispenser.getFacing(source.getBlockMetadata());
   IPosition var4 = BlockDispenser.getDispensePosition(source);
   ItemStack var5 = stack.splitStack(1);
   doDispense(source.getWorld(), var5, 6, var3, var4);
   return stack;
 }
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer entityPlayer,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    if (!world.isRemote) {
      if (entityPlayer.isSneaking())
        entityPlayer.openGui(
            ShadowCraftEvolved.instance, IDs.GuiIDs.Land_Mine.ordinal(), world, x, y, z);

      TileEntityLandMineMk3 te = (TileEntityLandMineMk3) world.getTileEntity(x, y, z);
      if (te.getCamouflage(side) != null) {
        ItemStack camoStack = te.getCamouflage(side);
        te.setCamouflage(null, side);
        EntityItem itemEntity = new EntityItem(world, x, y, z, camoStack);
        world.spawnEntityInWorld(itemEntity);
      } else {
        ItemStack playerItem = entityPlayer.getCurrentEquippedItem();

        if (playerItem != null) {
          ItemStack camoStack = playerItem.splitStack(1);
          te.setCamouflage(camoStack, side);
        }
      }
    }

    return true;
  }
Exemplo n.º 3
0
 /** Called upon block activation (right click on the block.) */
 @Override
 public boolean onBlockActivated(
     World world,
     int x,
     int y,
     int z,
     EntityPlayer player,
     int side,
     float hitX,
     float hitY,
     float hitZ) {
   if (!world.isRemote) {
     if (player.isSneaking()) {
       player.openGui(FullPower.instance, GuiHandler.GuiIDs.CAMO_MINE.ordinal(), world, x, y, z);
     }
     TileEntityCamoMine te = (TileEntityCamoMine) world.getTileEntity(x, y, z);
     if (te.getCamouflage(side) != null) {
       ItemStack camoStack = te.getCamouflage(side);
       te.setCamouflage(null, side);
       EntityItem itemEntity = new EntityItem(world, x, y, z, camoStack);
       LogHelper.info("StackSize=" + camoStack.stackSize);
       // Tell world this item needs to be spawned
       world.spawnEntityInWorld(itemEntity);
     } else {
       ItemStack playerItem = player.getCurrentEquippedItem();
       if (playerItem != null) {
         ItemStack camoStack = playerItem.splitStack(1); // Remove 1 from stack
         ChatHelper.send(camoStack.toString());
         te.setCamouflage(camoStack, side);
       }
     }
   }
   return true;
 }
  /** Dispense the specified stack, play the dispense sound and spawn particles. */
  public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) {
    EnumFacing enumfacing = BlockDispenser.getFacing(par1IBlockSource.getBlockMetadata());
    World world = par1IBlockSource.getWorld();
    double d0 = par1IBlockSource.getX() + (double) ((float) enumfacing.getFrontOffsetX() * 1.125F);
    double d1 = par1IBlockSource.getY() + (double) ((float) enumfacing.getFrontOffsetY() * 1.125F);
    double d2 = par1IBlockSource.getZ() + (double) ((float) enumfacing.getFrontOffsetZ() * 1.125F);
    int i = par1IBlockSource.getXInt() + enumfacing.getFrontOffsetX();
    int j = par1IBlockSource.getYInt() + enumfacing.getFrontOffsetY();
    int k = par1IBlockSource.getZInt() + enumfacing.getFrontOffsetZ();
    Material material = world.getBlockMaterial(i, j, k);
    double d3;

    if (Material.water.equals(material)) {
      d3 = 1.0D;
    } else {
      if (!Material.air.equals(material)
          || !Material.water.equals(world.getBlockMaterial(i, j - 1, k))) {
        return this.defaultDispenserItemBehavior.dispense(par1IBlockSource, par2ItemStack);
      }

      d3 = 0.0D;
    }

    EntityBoat entityboat = new EntityBoat(world, d0, d1 + d3, d2);
    world.spawnEntityInWorld(entityboat);
    par2ItemStack.splitStack(1);
    return par2ItemStack;
  }
Exemplo n.º 5
0
  public static ItemStack copyStack(ItemStack itemstack, int i) {
    if (itemstack == null) {
      return null;
    }

    itemstack.stackSize += i;
    return itemstack.splitStack(i);
  }
Exemplo n.º 6
0
 public static ItemStack addToEmptyInventorySlot(IInventory inventory, int slot, ItemStack stack) {
   if (!inventory.isItemValidForSlot(slot, stack)) {
     return stack;
   }
   int stackLimit = inventory.getInventoryStackLimit();
   inventory.setInventorySlotContents(
       slot, copyStackWithAmount(stack, Math.min(stack.stackSize, stackLimit)));
   return stackLimit >= stack.stackSize ? null : stack.splitStack(stack.stackSize - stackLimit);
 }
 @Override
 public ItemStack decrStackSize(final int slot, final int amount) {
   ItemStack stack = getStackInSlot(slot);
   if (stack != null)
     if (stack.stackSize > amount) {
       stack = stack.splitStack(amount);
       onInventoryChanged();
     } else setInventorySlotContents(slot, null);
   return stack;
 }
Exemplo n.º 8
0
 /** Inserts the target stack and returns what didn't fit. */
 public ItemStack put(ItemStack stack) {
   int amount = Math.min(_max - _size, stack.stackSize);
   if (amount <= 0) return stack;
   Key k = Key.of(stack);
   Integer current = _elements.get(k);
   _elements.put(k, current == null ? amount : current + amount);
   _size += amount;
   stack.splitStack(amount);
   return stack.stackSize > 0 ? stack : null;
 }
Exemplo n.º 9
0
 @Override
 public ItemStack decrStackSize(int slot, int amount) {
   ItemStack stack = getStackInSlot(slot);
   if (stack != null)
     if (stack.stackSize > amount) {
       stack = stack.splitStack(amount);
       markDirty();
     } else {
       setInventorySlotContents(slot, null);
     }
   return stack;
 }
Exemplo n.º 10
0
 @Override
 public ItemStack decrStackSize(int index, int count) {
   ItemStack itemstack = getStackInSlot(index);
   if (itemstack != null) {
     if (itemstack.stackSize <= count) {
       setInventorySlotContents(index, null);
     }
     itemstack = itemstack.splitStack(count);
   }
   worldObj.markBlockForUpdate(this.getPos());
   return itemstack;
 }
Exemplo n.º 11
0
 @Override
 public ItemStack decrStackSize(int slot, int qty) {
   ItemStack stack = inventory[slot];
   if (stack != null) {
     if (stack.stackSize <= qty) inventory[slot] = null;
     else {
       stack = stack.splitStack(qty);
       if (stack.stackSize == 0) inventory[slot] = null;
     }
   }
   return stack;
 }
 @Override
 public ItemStack decrStackSize(int slot, int amount) {
   ItemStack stack = getStackInSlot(slot);
   if (stack != null) {
     if (stack.stackSize > amount) {
       stack = stack.splitStack(amount);
       markDirty();
     } else {
       inventory[slot] = null;
     }
   }
   return stack;
 }
 @Override
 public ItemStack decrStackSize(int slot, int amount) {
   if (!formed) return null;
   if (master() != null) return master().decrStackSize(slot, amount);
   ItemStack stack = getStackInSlot(slot);
   if (stack != null)
     if (stack.stackSize <= amount) setInventorySlotContents(slot, null);
     else {
       stack = stack.splitStack(amount);
       if (stack.stackSize == 0) setInventorySlotContents(slot, null);
     }
   return stack;
 }
Exemplo n.º 14
0
 @Override
 public ItemStack decrStackSize(int index, int count) {
   ItemStack stack = getStackInSlot(index);
   if (stack != null) {
     if (stack.stackSize > count) {
       stack = stack.splitStack(count);
       this.markDirty();
     } else {
       setInventorySlotContents(index, null);
     }
   }
   return stack;
 }
Exemplo n.º 15
0
 public ItemStack put(ItemStack stack) {
   log.debug("put", "stack", stack, "size", stack.stackSize);
   if (stack == null) return null;
   Key key = Key.of(stack);
   Element e = _elements.get(key);
   if (e == null) return stack;
   int amount = stack.stackSize;
   amount = Math.min(amount, _maxTotal - _total);
   amount = e.put(amount, _maxPerKey);
   if (amount == 0) return stack;
   _total += amount;
   log.debug("put: done", "amount", amount);
   return stack.splitStack(amount);
 }
  @Override
  public ItemStack dispenseStack(IBlockSource block, ItemStack stack) {
    EnumFacing enumfacing = BlockDispenser.func_149937_b(block.getBlockMetadata());
    double d0 = block.getX() + enumfacing.getFrontOffsetX();
    double d1 = block.getYInt() + 0.2F;
    double d2 = block.getZ() + enumfacing.getFrontOffsetZ();
    Entity entity = ItemEntityEgg.spawnEntity(block.getWorld(), stack.getItemDamage(), d0, d1, d2);

    if (entity instanceof EntityLivingBase && stack.hasDisplayName())
      ((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());

    stack.splitStack(1);
    return stack;
  }
Exemplo n.º 17
0
 @Override
 public ItemStack decrStackSize(int slot, int amount) {
   ItemStack stack = getStackInSlot(slot);
   if (stack != null) {
     if (stack.stackSize > amount) {
       stack = stack.splitStack(amount);
       // Don't forget this line or your inventory will not be saved!
       this.onInventoryChanged();
     } else {
       setInventorySlotContents(slot, null);
     }
   }
   return stack;
 }
Exemplo n.º 18
0
 public static ItemStack addToOccupiedSlot(
     IInventory inventory, int slot, ItemStack stack, ItemStack existingStack) {
   int stackLimit = Math.min(inventory.getInventoryStackLimit(), stack.getMaxStackSize());
   if (stack.stackSize + existingStack.stackSize > stackLimit) {
     int stackDiff = stackLimit - existingStack.stackSize;
     existingStack.stackSize = stackLimit;
     stack.stackSize -= stackDiff;
     inventory.setInventorySlotContents(slot, existingStack);
     return stack;
   }
   existingStack.stackSize += Math.min(stack.stackSize, stackLimit);
   inventory.setInventorySlotContents(slot, existingStack);
   return stackLimit >= stack.stackSize ? null : stack.splitStack(stack.stackSize - stackLimit);
 }
Exemplo n.º 19
0
  @Override
  public ItemStack decrStackSize(int i, int j) {

    ItemStack itemstack = getStackInSlot(i);

    if (itemstack != null) {
      if (itemstack.stackSize <= j) {
        setInventorySlotContents(i, null);
      } else {
        itemstack = itemstack.splitStack(j);
      }
    }
    return itemstack;
  }
Exemplo n.º 20
0
 /**
  * Decreases the size of the stack in the specified slot
  *
  * @param index the index of the slot
  * @param amount the amount to decrease the stack by
  * @return the resulting itemstack
  */
 @Override
 public ItemStack decrStackSize(int index, int amount) {
   ItemStack itemStack = getStackInSlot(index);
   if (itemStack != null) {
     if (itemStack.stackSize <= amount) {
       setInventorySlotContents(index, null);
     } else {
       ItemStack splitStack = itemStack.splitStack(amount);
       if (splitStack.stackSize == 0) {
         setInventorySlotContents(index, null);
       }
     }
   }
   return itemStack;
 }
  @Override
  public ItemStack decrStackSize(int slot, int amount) {
    ItemStack stack = getStackInSlot(slot);

    if (stack != null) {
      if (stack.stackSize > amount) {
        stack = stack.splitStack(amount);
        this.onInventoryChanged();
      } else {
        setInventorySlotContents(slot, null);
      }
    }

    return stack;
  }
 @Override
 public ItemStack decrStackSize(int slot, int amount) {
   if (!formed) return null;
   TileEntityBottlingMachine master = master();
   if (master != null) return master.decrStackSize(slot, amount);
   ItemStack stack = getStackInSlot(slot);
   if (stack != null)
     if (stack.stackSize <= amount) setInventorySlotContents(slot, null);
     else {
       stack = stack.splitStack(amount);
       if (stack.stackSize == 0) setInventorySlotContents(slot, null);
     }
   this.markDirty();
   return stack;
 }
  public ItemStack dispenseStack(IBlockSource BlockSource, ItemStack stack) {
    EnumFacing enumfacing = BlockDispenser.getFacing(BlockSource.getBlockMetadata());
    double d0 = BlockSource.getX() + (double) enumfacing.getFrontOffsetX();
    double d1 = BlockSource.getY() + (double) enumfacing.getFrontOffsetY();
    double d2 = BlockSource.getZ() + (double) enumfacing.getFrontOffsetZ();
    Entity entity =
        ItemGaiaSpawnEgg.spawnCreature(BlockSource.getWorld(), stack.getItemDamage(), d0, d1, d2);

    if (entity instanceof EntityLivingBase && stack.hasDisplayName()) {
      ((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());
    }

    stack.splitStack(1);
    return stack;
  }
Exemplo n.º 24
0
 @Override
 public ItemStack decrStackSize(int var1, int var2) {
   ItemStack stack = this.getStackInSlot(var1);
   if (stack != null) {
     if (stack.stackSize <= var2) {
       this.setInventorySlotContents(var1, null);
     } else {
       stack = stack.splitStack(var2);
       if (stack.stackSize == 0) {
         this.setInventorySlotContents(var1, null);
       }
     }
   }
   return stack;
 }
 @Override
 public ItemStack decrStackSize(int slot, int amt) {
   ItemStack stack = getStackInSlot(slot);
   if (stack != null) {
     if (stack.stackSize <= amt) {
       setInventorySlotContents(slot, null);
     } else {
       stack = stack.splitStack(amt);
       if (stack.stackSize == 0) {
         setInventorySlotContents(slot, null);
       }
     }
   }
   return stack;
 }
  @Override
  public ItemStack decrStackSize(int slotIndex, int decrementAmount) {
    ItemStack itemStack = getStackInSlot(slotIndex);
    if (itemStack != null) {
      if (itemStack.stackSize <= decrementAmount) {
        setInventorySlotContents(slotIndex, null);
      } else {
        itemStack = itemStack.splitStack(decrementAmount);
        if (itemStack.stackSize == 0) {
          setInventorySlotContents(slotIndex, null);
        }
      }
    }

    return itemStack;
  }
Exemplo n.º 27
0
 @Override
 public ItemStack decrStackSize(int aIndex, int aAmount) {
   ItemStack rStack = getStackInSlot(aIndex);
   if (rStack != null) {
     if (rStack.stackSize <= aAmount) {
       if (setStackToZeroInsteadOfNull(aIndex)) rStack.stackSize = 0;
       else setInventorySlotContents(aIndex, null);
     } else {
       rStack = rStack.splitStack(aAmount);
       if (rStack.stackSize == 0) {
         if (!setStackToZeroInsteadOfNull(aIndex)) setInventorySlotContents(aIndex, null);
       }
     }
   }
   return rStack;
 }
 @Override
 public ItemStack decrStackSize(int slot, int amount) {
   ItemStack stack = this.brewingItemStacks[slot];
   if (stack != null) {
     if (stack.stackSize <= amount) {
       this.setInventorySlotContents(slot, null);
       return stack;
     } else {
       ItemStack stack1 = stack.splitStack(amount);
       if (stack.stackSize <= 0) {
         this.setInventorySlotContents(slot, null);
       }
       return stack1;
     }
   }
   return null;
 }
 @Override
 public void onPickupFromSlot(EntityPlayer player, ItemStack stack) {
   container.needCraftingUpdate = false;
   switch (container.state) {
     case DECOMPOSING:
       if (inventory == container.invInput
           && container.getSlot(SequenceProgrammerContainer.OUT).getHasStack()
           && stack.stackSize > 1) {
         putStack(stack.splitStack(1));
         container.pendingCount = 0;
       }
     default:
       break;
   }
   container.needCraftingUpdate = true;
   super.onPickupFromSlot(player, stack);
 }
  /**
   * Removes some of the units from itemstack in the given slot, and returns as a separate itemstack
   *
   * @param slotIndex the slot number to remove the items from
   * @param count the number of units to remove
   * @return a new itemstack containing the units removed from the slot
   */
  @Override
  public ItemStack decrStackSize(int slotIndex, int count) {
    ItemStack itemStackInSlot = getStackInSlot(slotIndex);
    if (itemStackInSlot == null) return null;

    ItemStack itemStackRemoved;
    if (itemStackInSlot.stackSize <= count) {
      itemStackRemoved = itemStackInSlot;
      setInventorySlotContents(slotIndex, null);
    } else {
      itemStackRemoved = itemStackInSlot.splitStack(count);
      if (itemStackInSlot.stackSize == 0) {
        setInventorySlotContents(slotIndex, null);
      }
    }
    markDirty();
    return itemStackRemoved;
  }