コード例 #1
0
 @Override
 public void onEaten(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) {
   aStack.stackSize--;
   ItemStack tStack = GT_OreDictUnificator.get(GT_Utility.copy(mEmptyContainer));
   if (tStack != null && !aPlayer.inventory.addItemStackToInventory(tStack))
     aPlayer.dropPlayerItemWithRandomChoice(tStack, true);
   aPlayer.worldObj.playSoundAtEntity(
       aPlayer, "random.burp", 0.5F, aPlayer.worldObj.rand.nextFloat() * 0.1F + 0.9F);
   if (!aPlayer.worldObj.isRemote) {
     if (mMilk) {
       aPlayer.curePotionEffects(new ItemStack(Items.milk_bucket, 1, 0));
     }
     for (int i = 3; i < mPotionEffects.length; i += 4) {
       if (aPlayer.worldObj.rand.nextInt(100) < mPotionEffects[i]) {
         aPlayer.addPotionEffect(
             new PotionEffect(
                 mPotionEffects[i - 3],
                 mPotionEffects[i - 2],
                 mPotionEffects[i - 1],
                 mInvisibleParticles));
       }
     }
     if (mExplosive) {
       aPlayer.worldObj.newExplosion(
           aPlayer, aPlayer.posX, aPlayer.posY, aPlayer.posZ, 4, true, true);
       aPlayer.attackEntityFrom(GT_DamageSources.getExplodingDamage(), Float.MAX_VALUE);
     }
   }
 }
コード例 #2
0
 /**
  * @param aFoodLevel Amount of Food in Half Bacon [0 - 20]
  * @param aSaturation Amount of Saturation [0.0F - 1.0F]
  * @param aAction The Action to be used. If this is null, it uses the Eating Action
  * @param aEmptyContainer An empty Container (Optional)
  * @param aAlwaysEdible If this Item is always edible, like Golden Apples or Potions
  * @param aInvisibleParticles If the Particles of the Potion Effects are invisible
  * @param aPotionEffects An Array of Potion Effects with %4==0 Elements as follows ID of a Potion
  *     Effect. 0 for none Duration of the Potion in Ticks Level of the Effect. [0, 1, 2] are for
  *     [I, II, III] The likelihood that this Potion Effect takes place upon being eaten [1 - 100]
  */
 public GT_FoodStat(
     int aFoodLevel,
     float aSaturation,
     EnumAction aAction,
     ItemStack aEmptyContainer,
     boolean aAlwaysEdible,
     boolean aInvisibleParticles,
     boolean aIsRotten,
     int... aPotionEffects) {
   mFoodLevel = aFoodLevel;
   mSaturation = aSaturation;
   mAction = aAction == null ? EnumAction.eat : aAction;
   mPotionEffects = aPotionEffects;
   mEmptyContainer = GT_Utility.copy(aEmptyContainer);
   mInvisibleParticles = aInvisibleParticles;
   mAlwaysEdible = aAlwaysEdible;
   mIsRotten = aIsRotten;
 }
コード例 #3
0
  @Override
  public ItemStack getCraftingResult(InventoryCrafting aGrid) {
    ItemStack rStack = super.getCraftingResult(aGrid);
    if (rStack != null) {
      // Update the Stack
      GT_Utility.updateItemStack(rStack);

      // Keeping NBT
      if (mKeepingNBT)
        for (int i = 0; i < aGrid.getSizeInventory(); i++) {
          if (aGrid.getStackInSlot(i) != null && aGrid.getStackInSlot(i).hasTagCompound()) {
            rStack.setTagCompound((NBTTagCompound) aGrid.getStackInSlot(i).getTagCompound().copy());
            break;
          }
        }

      // Charge Values
      if (GT_ModHandler.isElectricItem(rStack)) {
        GT_ModHandler.dischargeElectricItem(
            rStack, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false, true);
        int tCharge = 0;
        for (int i = 0; i < aGrid.getSizeInventory(); i++)
          tCharge +=
              GT_ModHandler.dischargeElectricItem(
                  aGrid.getStackInSlot(i), Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, true);
        if (tCharge > 0)
          GT_ModHandler.chargeElectricItem(rStack, tCharge, Integer.MAX_VALUE, true, false);
      }

      // Saving Ingredients inside the Item.
      if (mDismantleable) {
        NBTTagCompound rNBT = rStack.getTagCompound(), tNBT = new NBTTagCompound();
        if (rNBT == null) rNBT = new NBTTagCompound();
        for (int i = 0; i < 9; i++) {
          ItemStack tStack = aGrid.getStackInSlot(i);
          if (tStack != null
              && GT_Utility.getContainerItem(tStack, true) == null
              && !(tStack.getItem() instanceof GT_MetaGenerated_Tool)) {
            tStack = GT_Utility.copyAmount(1, tStack);
            GT_ModHandler.dischargeElectricItem(
                tStack, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false, true);
            tNBT.setTag("Ingredient." + i, tStack.writeToNBT(new NBTTagCompound()));
          }
        }
        rNBT.setTag("GT.CraftingComponents", tNBT);
        rStack.setTagCompound(rNBT);
      }

      // Add Enchantments
      for (int i = 0; i < mEnchantmentsAdded.length; i++)
        GT_Utility.ItemNBT.addEnchantment(
            rStack,
            mEnchantmentsAdded[i],
            EnchantmentHelper.getEnchantmentLevel(mEnchantmentsAdded[i].effectId, rStack)
                + mEnchantmentLevelsAdded[i]);

      // Update the Stack again
      GT_Utility.updateItemStack(rStack);
    }
    return rStack;
  }