public boolean tryFireMinigun(EntityLivingBase target) {
   boolean lastShotOfAmmo = false;
   if (ammo != null && (pressurizable == null || pressurizable.getPressure(stack) > 0)) {
     setMinigunTriggerTimeOut(Math.max(10, getMinigunSoundCounter()));
     if (getMinigunSpeed() == MAX_GUN_SPEED && (!requiresTarget || gunAimedAtTarget)) {
       if (!requiresTarget) target = raytraceTarget();
       lastShotOfAmmo = ammo.attemptDamageItem(1, rand);
       if (pressurizable != null) pressurizable.addAir(stack, -airUsage);
       if (target != null) {
         ItemStack potion = ItemGunAmmo.getPotion(ammo);
         if (potion != null) {
           if (rand.nextInt(20) == 0) {
             List<PotionEffect> effects = Items.potionitem.getEffects(potion);
             if (effects != null) {
               for (PotionEffect effect : effects) {
                 target.addPotionEffect(new PotionEffect(effect));
               }
             }
           }
         } else {
           target.attackEntityFrom(DamageSource.causePlayerDamage(player), 4);
         }
       }
     }
   }
   return lastShotOfAmmo;
 }
示例#2
0
 @Override
 public boolean onItemUse(
     ItemStack stack,
     EntityPlayer player,
     World world,
     int x,
     int y,
     int z,
     int side,
     float hitX,
     float hitY,
     float hitZ) {
   destroy(world, x, y, z, side, player);
   stack.attemptDamageItem(1, world.rand);
   return true;
 }
示例#3
0
  private List<ItemStack> dropInventory(EntityPlayer player) {
    List<ItemStack> itemsToDrop = new ArrayList<ItemStack>();

    if (player.inventory.mainInventory.length > 8) {
      /* Array to determine the order the inventory array is processed. */
      int[] placeArray = new int[player.inventory.mainInventory.length - 9];
      for (int i = 0; i < placeArray.length; i++) {
        placeArray[i] = i + 9;
      }
      shuffleArray(placeArray, player.worldObj.rand);

      int countDrops = 0;
      for (int i = 0; i < placeArray.length; ++i) {
        int slot = placeArray[i];
        ItemStack itemStack = player.inventory.mainInventory[slot];
        if (itemStack == null || itemBlacklist.isItemBlacklisted(itemStack)) {
          continue;
        }
        boolean shouldDrop = false;
        if ((inventoryMaxDrop == 0 || countDrops < inventoryMaxDrop)
            && inventoryDropChance - player.worldObj.rand.nextInt(100) >= 1) {
          shouldDrop = true;
        }
        int percentDamage =
            shouldDrop ? inventoryDeathDamage + inventoryDropDamage : inventoryDeathDamage;
        percentDamage = percentDamage > 100 ? 100 : percentDamage;
        itemStack.attemptDamageItem(
            itemStack.getMaxDamage() * percentDamage / 100, player.worldObj.rand);

        boolean itemDestroyed =
            itemStack.isItemStackDamageable()
                && itemStack.getItemDamage() > itemStack.getMaxDamage();
        if (itemDestroyed) {
          player.inventory.mainInventory[slot] = null;
        }

        if (shouldDrop) {
          if (!itemDestroyed) {
            itemsToDrop.add(itemStack);
          }
          player.inventory.mainInventory[slot] = null;
          countDrops++;
        }
      }
    }
    return itemsToDrop;
  }
  // 右クリック処理
  @Override
  public boolean onBlockActivated(
      World par1World,
      int par2,
      int par3,
      int par4,
      EntityPlayer par5EntityPlayer,
      int par6,
      float par7,
      float par8,
      float par9) {
    ItemStack itemstack = par5EntityPlayer.inventory.getCurrentItem();
    int meta = par1World.getBlockMetadata(par2, par3, par4);
    TileIncenseBase tile = (TileIncenseBase) par1World.getTileEntity(par2, par3, par4);

    AMTBlockRightClickEvent event =
        new AMTBlockRightClickEvent(par1World, par5EntityPlayer, itemstack, par2, par3, par4);
    MinecraftForge.EVENT_BUS.post(event);

    if (event.isCanceled()) {
      return true;
    }

    if (itemstack == null) // 回収動作
    {
      if (!par5EntityPlayer.inventory.addItemStackToInventory(new ItemStack(this, 1))) {
        if (!par1World.isRemote) par5EntityPlayer.entityDropItem(new ItemStack(this, 1), 1);
      }

      par1World.setBlockToAir(par2, par3, par4);
      par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
      return true;
    } else if (itemstack.getItem() == Item.getItemFromBlock(this)) {
      if (!par1World.isRemote) {
        EntityItem entity =
            new EntityItem(
                par1World,
                par5EntityPlayer.posX,
                par5EntityPlayer.posY,
                par5EntityPlayer.posZ,
                new ItemStack(this, 1));
        par1World.spawnEntityInWorld(entity);
      }

      par1World.setBlockToAir(par2, par3, par4);
      par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
      return true;
    } else if (itemstack.getItem() instanceof IIncenseEffect) // お香アイテムの場合
    {
      if (tile != null && !tile.hasItem()) {
        ItemStack put = itemstack.copy();
        tile.setItemstack(put);
        if (!par5EntityPlayer.capabilities.isCreativeMode
            && (itemstack.stackSize - put.stackSize) <= 0) {
          par5EntityPlayer.inventory.setInventorySlotContents(
              par5EntityPlayer.inventory.currentItem, (ItemStack) null);
        }
        tile.markDirty();
        par5EntityPlayer.inventory.markDirty();
        par1World.markBlockForUpdate(par2, par3, par4);
        par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
        return true;
      }
      return false;
    } else if (itemstack.getItem() == Items.flint_and_steel
        || itemstack.getItem() == DCsAppleMilk.firestarter) {
      if (tile != null && tile.hasItem() && !tile.getActive()) {
        par5EntityPlayer.triggerAchievement(AchievementRegister.useIncense);
        itemstack.attemptDamageItem(1, par1World.rand);
        tile.setActive();
        tile.markDirty();
        par1World.setBlockMetadataWithNotify(par2, par3, par4, 1, 3);
        par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
        par1World.scheduleBlockUpdate(par2, par3, par4, this, this.tickRate(par1World));
        return true;
      }
      return false;
    } else {
      return false;
    }
  }