Beispiel #1
0
  /** Called by a player entity when they collide with an entity */
  public void onCollideWithPlayer(EntityPlayer par1EntityPlayer) {
    if (!this.worldObj.isRemote) {
      ItemStack var2 = this.func_92014_d();
      int var3 = var2.stackSize;

      if (this.delayBeforeCanPickup == 0
          && par1EntityPlayer.inventory.addItemStackToInventory(var2)) {
        if (var2.itemID == Block.wood.blockID) {
          par1EntityPlayer.triggerAchievement(AchievementList.mineWood);
        }

        if (var2.itemID == Item.leather.itemID) {
          par1EntityPlayer.triggerAchievement(AchievementList.killCow);
        }

        if (var2.itemID == Item.diamond.itemID) {
          par1EntityPlayer.triggerAchievement(AchievementList.diamonds);
        }

        if (var2.itemID == Item.blazeRod.itemID) {
          par1EntityPlayer.triggerAchievement(AchievementList.blazeRod);
        }

        this.playSound(
            "random.pop",
            0.2F,
            ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
        par1EntityPlayer.onItemPickup(this, var3);

        if (var2.stackSize <= 0) {
          this.setDead();
        }
      }
    }
  }
  private void spawnBaby() {
    EntityAgeable var1 = this.theAnimal.createChild(this.targetMate);
    if (var1 != null) {
      EntityPlayer var2 = this.theAnimal.func_146083_cb();
      if (var2 == null && this.targetMate.func_146083_cb() != null) {
        var2 = this.targetMate.func_146083_cb();
      }

      if (var2 != null) {
        var2.triggerAchievement(StatList.animalsBredStat);
        if (this.theAnimal instanceof EntityCow) {
          var2.triggerAchievement(AchievementList.breedCow);
        }
      }

      this.theAnimal.setGrowingAge(6000);
      this.targetMate.setGrowingAge(6000);
      this.theAnimal.resetInLove();
      this.targetMate.resetInLove();
      var1.setGrowingAge(-24000);
      var1.setLocationAndAngles(
          this.theAnimal.posX, this.theAnimal.posY, this.theAnimal.posZ, 0.0F, 0.0F);
      this.theWorld.spawnEntityInWorld(var1);
      Random var3 = this.theAnimal.getRNG();

      for (int var4 = 0; var4 < 7; ++var4) {
        double var5 = var3.nextGaussian() * 0.02D;
        double var7 = var3.nextGaussian() * 0.02D;
        double var9 = var3.nextGaussian() * 0.02D;
        this.theWorld.spawnParticle(
            EnumParticleTypes.HEART,
            this.theAnimal.posX
                + (double) (var3.nextFloat() * this.theAnimal.width * 2.0F)
                - (double) this.theAnimal.width,
            this.theAnimal.posY + 0.5D + (double) (var3.nextFloat() * this.theAnimal.height),
            this.theAnimal.posZ
                + (double) (var3.nextFloat() * this.theAnimal.width * 2.0F)
                - (double) this.theAnimal.width,
            var5,
            var7,
            var9,
            new int[0]);
      }

      if (this.theWorld.getGameRules().getGameRuleBooleanValue("doMobLoot")) {
        this.theWorld.spawnEntityInWorld(
            new EntityXPOrb(
                this.theWorld,
                this.theAnimal.posX,
                this.theAnimal.posY,
                this.theAnimal.posZ,
                var3.nextInt(7) + 1));
      }
    }
  }
Beispiel #3
0
 @Override
 public ItemStack onEaten(ItemStack item, World world, EntityPlayer player) {
   super.onEaten(item, world, player);
   if (item.getItem() == ItemsFood.chickenDinner)
     player.triggerAchievement(DivineRPGAchievements.mealToRemember);
   return item;
 }
  public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
    MovingObjectPosition var4 = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, false);
    if (var4 != null
        && var4.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK
        && worldIn.getBlockState(var4.func_178782_a()).getBlock() == Blocks.end_portal_frame) {
      return itemStackIn;
    } else {
      if (!worldIn.isRemote) {
        BlockPos var5 = worldIn.func_180499_a("Stronghold", new BlockPos(playerIn));
        if (var5 != null) {
          EntityEnderEye var6 =
              new EntityEnderEye(worldIn, playerIn.posX, playerIn.posY, playerIn.posZ);
          var6.func_180465_a(var5);
          worldIn.spawnEntityInWorld(var6);
          worldIn.playSoundAtEntity(
              playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
          worldIn.playAuxSFXAtEntity((EntityPlayer) null, 1002, new BlockPos(playerIn), 0);
          if (!playerIn.capabilities.isCreativeMode) {
            --itemStackIn.stackSize;
          }

          playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
        }
      }

      return itemStackIn;
    }
  }
  public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
    if (playerIn.isSneaking()) {
      if (!playerIn.capabilities.isCreativeMode) {
        --itemStackIn.stackSize;
      }

      worldIn.playSoundAtEntity(
          playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

      if (!worldIn.isRemote) {
        // EntityEnchantedEbonheart

        worldIn.spawnEntityInWorld(new EntityEnchantedEbonheart(worldIn, playerIn));

        // EntityEnchantedEbonheart entityenchantedebonheart = new EntityEnchantedEbonheart(worldIn,
        // playerIn);
        // entityenchantedebonheart.setHeadingFromThrower(playerIn, playerIn.rotationPitch,
        // playerIn.rotationYaw, -20.0F, 0.7F, 1.0F);
        // worldIn.spawnEntityInWorld(entityenchantedebonheart);

        // EntityExpBottle entityexpbottle = new EntityExpBottle(worldIn, playerIn);
        // entityexpbottle.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw,
        // -20.0F, 0.7F, 1.0F);
        // worldIn.spawnEntityInWorld(entityexpbottle);
      }

      playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
      return itemStackIn;
    }
    return itemStackIn;
  }
 @Override
 public void handleFairyUpgrade(EntityItem item, EntityPlayer player, TileEntityDungeonCore core) {
   if (PlayerUtils.hasItem(player, ZSSItems.swordMasterTrue)) {
     item.setDead();
     player.triggerAchievement(ZSSAchievements.shieldMirror);
     WorldUtils.spawnItemWithRandom(
         core.getWorldObj(),
         new ItemStack(ZSSItems.shieldMirror),
         core.xCoord,
         core.yCoord + 2,
         core.zCoord);
     core.getWorldObj()
         .playSoundEffect(
             core.xCoord + 0.5D,
             core.yCoord + 1,
             core.zCoord + 0.5D,
             Sounds.SECRET_MEDLEY,
             1.0F,
             1.0F);
   } else {
     core.getWorldObj()
         .playSoundEffect(
             core.xCoord + 0.5D,
             core.yCoord + 1,
             core.zCoord + 0.5D,
             Sounds.FAIRY_LAUGH,
             1.0F,
             1.0F);
     PlayerUtils.sendTranslatedChat(player, "chat.zss.fairy.laugh.sword");
   }
 }
 /**
  * Trigger an event
  *
  * @param player The player
  * @param achname The name of the achievement
  * @return true if succeeded
  */
 public static boolean trigger(EntityPlayer player, String achid) {
   ACAchievement ach = ACAchievement.getById(achid);
   if (ach == null) {
     AcademyCraft.log.warn("AC Achievement '" + achid + "' does not exist");
     return false;
   }
   player.triggerAchievement(ach);
   return true;
 }
  @Override
  public ItemStack onEaten(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    if (!par2World.isRemote) {
      this.addSSMoisture(4, 3F, par3EntityPlayer);
    }
    par3EntityPlayer.triggerAchievement(AchievementRegister.drinkCocktail);

    return super.onEaten(par1ItemStack, par2World, par3EntityPlayer);
  }
 // set entity burn if that waling on.
 public void onEntityCollidedWithBlock(
     World par1World, int par2, int par3, int par4, Entity par5Entity) {
   if (this.getUnderMaterial(par1World, par2, par3, par4)
       && (par5Entity instanceof EntityLiving || par5Entity instanceof EntityPlayer)) {
     par5Entity.setFire(30);
     if (par5Entity instanceof EntityPlayer) {
       ((EntityPlayer) par5Entity).triggerAchievement(AchievementRegister.burnOnTeppan);
     }
   }
 }
 @Override
 public boolean changeMode(EntityPlayer pentityplayer) {
   ItemStack litemstack = owner.maidInventory.getStackInSlot(0);
   if (litemstack != null) {
     if (litemstack.getItem() instanceof ItemBow
         || LMM_TriggerSelect.checkWeapon(owner.getMaidMaster(), "Bow", litemstack)) {
       if (owner.maidInventory.getInventorySlotContainItem(ItemFlintAndSteel.class) > -1) {
         owner.setMaidMode("Blazingstar");
         if (LMM_LittleMaidMobNX.ac_BlazingStar != null) {
           pentityplayer.triggerAchievement(LMM_LittleMaidMobNX.ac_BlazingStar);
         }
       } else {
         owner.setMaidMode("Archer");
         if (LMM_LittleMaidMobNX.ac_Archer != null) {
           pentityplayer.triggerAchievement(LMM_LittleMaidMobNX.ac_Archer);
         }
       }
       return true;
     }
   }
   return false;
 }
  public void onPlayerStoppedUsing(
      ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft) {
    boolean var5 =
        playerIn.capabilities.isCreativeMode
            || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
    if (var5 || playerIn.inventory.hasItem(Items.arrow)) {
      int var6 = this.getMaxItemUseDuration(stack) - timeLeft;
      float var7 = (float) var6 / 20.0F;
      var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;
      if ((double) var7 < 0.1D) {
        return;
      }

      if (var7 > 1.0F) {
        var7 = 1.0F;
      }

      EntityArrow var8 = new EntityArrow(worldIn, playerIn, var7 * 2.0F);
      if (var7 == 1.0F) {
        var8.setIsCritical(true);
      }

      int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
      if (var9 > 0) {
        var8.setDamage(var8.getDamage() + (double) var9 * 0.5D + 0.5D);
      }

      int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
      if (var10 > 0) {
        var8.setKnockbackStrength(var10);
      }

      if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) {
        var8.setFire(100);
      }

      stack.damageItem(1, playerIn);
      worldIn.playSoundAtEntity(
          playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F);
      if (var5) {
        var8.canBePickedUp = 2;
      } else {
        playerIn.inventory.consumeInventoryItem(Items.arrow);
      }

      playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
      if (!worldIn.isRemote) {
        worldIn.spawnEntityInWorld(var8);
      }
    }
  }
  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 currentMeta = par1World.getBlockMetadata(par2, par3, par4);
    int bottomBlockID = par1World.getBlockId(par2, par3 - 1, par4);
    Block block = Block.blocksList[bottomBlockID];

    if (itemstack == null) {
      if (!par5EntityPlayer.inventory.addItemStackToInventory(
          new ItemStack(DCsAppleMilk.emptyPan, 1, 0))) {
        par5EntityPlayer.entityDropItem(new ItemStack(DCsAppleMilk.emptyPan, 1, 0), 1);
      }

      par1World.setBlockToAir(par2, par3, par4);
      par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
      return true;
    } else if (itemstack.itemID == DCsAppleMilk.emptyPan.blockID) {
      if (!par5EntityPlayer.inventory.addItemStackToInventory(
          new ItemStack(DCsAppleMilk.emptyPan, 1))) {
        par5EntityPlayer.entityDropItem(new ItemStack(DCsAppleMilk.emptyPan, 1), 1);
      }

      par1World.setBlockToAir(par2, par3, par4);
      par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
      return true;
    } else if (itemstack.itemID == Item.bowlEmpty.itemID) {
      return true;
    } else {
      int ID = itemstack.itemID;
      int IDm = itemstack.getItemDamage();
      int setMeta = this.getMakerMeta(ID, IDm);

      if ((setMeta > 0)
          && (bottomBlockID == Block.furnaceBurning.blockID || block instanceof BlockFurnace)) {
        this.setPanMeta(par1World, par2, par3, par4, par5EntityPlayer, itemstack, setMeta);
        par5EntityPlayer.triggerAchievement(AchievementRegister.makeRice);
        return true;
      } else {
        return false;
      }
    }
  }
  /** Called when the mob's health reaches 0. */
  public void onDeath(DamageSource p_70645_1_) {
    super.onDeath(p_70645_1_);

    if (p_70645_1_.getSourceOfDamage() instanceof EntityThrownApple
        && p_70645_1_.getEntity() instanceof EntityPlayer) {
      EntityPlayer entityplayer = (EntityPlayer) p_70645_1_.getEntity();
      double d0 = entityplayer.posX - this.posX;
      double d1 = entityplayer.posZ - this.posZ;

      if (d0 * d0 + d1 * d1 >= 2500.0D) {
        entityplayer.triggerAchievement(AchievementList.snipeSkeleton);
      }
    }
  }
  /** Called when the mob's health reaches 0. */
  @Override
  public void onDeath(DamageSource par1DamageSource) {
    super.onDeath(par1DamageSource);

    if (par1DamageSource.getSourceOfDamage() instanceof EntityArrow
        && par1DamageSource.getEntity() instanceof EntityPlayer) {
      final EntityPlayer var2 = (EntityPlayer) par1DamageSource.getEntity();
      final double var3 = var2.posX - this.posX;
      final double var5 = var2.posZ - this.posZ;

      if (var3 * var3 + var5 * var5 >= 2500.0D) {
        var2.triggerAchievement(AchievementList.snipeSkeleton);
      }
    }
  }
  public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
    if (playerIn.capabilities.isCreativeMode) {
      return itemStackIn;
    } else {
      --itemStackIn.stackSize;
      worldIn.playSoundAtEntity(
          playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
      if (!worldIn.isRemote) {
        worldIn.spawnEntityInWorld(new EntityEnderPearl(worldIn, playerIn));
      }

      playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
      return itemStackIn;
    }
  }
Beispiel #16
0
  /**
   * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit
   * by a player. @param par2 - Level of Looting used to kill this mob.
   */
  protected void dropFewItems(boolean p_70628_1_, int p_70628_2_) {
    this.dropItem(Items.nether_star, 1);

    if (!this.worldObj.isRemote) {
      Iterator iterator =
          this.worldObj
              .getEntitiesWithinAABB(
                  EntityPlayer.class, this.boundingBox.expand(50.0D, 100.0D, 50.0D))
              .iterator();

      while (iterator.hasNext()) {
        EntityPlayer entityplayer = (EntityPlayer) iterator.next();
        entityplayer.triggerAchievement(AchievementList.field_150964_J);
      }
    }
  }
 @Override
 public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
   TileEntityPresent present = (TileEntityPresent) world.getTileEntity(pos);
   if (present != null) {
     world.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "random.levelup", 0.75F, 1.0F);
     player.addChatComponentMessage(
         new ChatComponentText(
             EnumChatFormatting.GREEN
                 + "Merry Christmas"
                 + EnumChatFormatting.RESET
                 + " from "
                 + EnumChatFormatting.RED
                 + present.ownerName));
     player.triggerAchievement(FurnitureAchievements.unwrapPresent);
   }
 }
 public void harvestBlock(
     World worldIn, EntityPlayer playerIn, BlockPos pos, IBlockState state, TileEntity te) {
   if (!worldIn.isRemote
       && playerIn.getCurrentEquippedItem() != null
       && playerIn.getCurrentEquippedItem().getItem() == Items.shears) {
     playerIn.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
     spawnAsEntity(
         worldIn,
         pos,
         new ItemStack(
             Item.getItemFromBlock(this),
             1,
             ((BlockPlanks.EnumType) state.getValue(VARIANT_PROP)).func_176839_a()));
   } else {
     super.harvestBlock(worldIn, playerIn, pos, state, te);
   }
 }
  @Override
  public boolean itemInteractionForEntity(
      ItemStack item, EntityPlayer player, EntityLivingBase entity) {

    player.triggerAchievement(ContentHandler.achDataChecker);

    if (player.worldObj.isRemote) return false;

    String outputString =
        StatCollector.translateToLocal("chat.colorfulmobs.name")
            + ": "
            + EntityList.getEntityString(entity)
            + " ";

    if (ColorProperties.hasProperties(entity)) {

      ColorProperties obj = ColorProperties.getProperties(entity);
      outputString =
          outputString
              + EnumChatFormatting.RED
              + StatCollector.translateToLocal("chat.colorfulmobs.red")
              + ": "
              + (int) (obj.getColorObj().getRed() * 255)
              + " "
              + EnumChatFormatting.GREEN
              + StatCollector.translateToLocal("chat.colorfulmobs.green")
              + ": "
              + (int) (obj.getColorObj().getGreen() * 255)
              + " "
              + EnumChatFormatting.BLUE
              + StatCollector.translateToLocal("chat.colorfulmobs.blue")
              + ": "
              + (int) (obj.getColorObj().getBlue() * 255)
              + " "
              + EnumChatFormatting.RESET
              + StatCollector.translateToLocal("chat.colorfulmobs.transparency")
              + ": "
              + (100 - (int) (obj.getColorObj().getAlpha() * 100))
              + "%";
      obj.sync();
    }

    player.addChatMessage(new ChatComponentText(outputString));
    return true;
  }
  private boolean lootTarget(EntityPlayer player, EntityLivingBase target) {
    if (target.getEntityData().getBoolean("LootableEntityFlag")) {
      return false;
    }
    IEntityLootable lootable =
        (target instanceof IEntityLootable ? (IEntityLootable) target : null);
    float lootChance =
        (lootable != null
            ? lootable.getLootableChance(player, getType())
            : LootableEntityRegistry.getEntityLootChance(target.getClass()));
    lootChance *= Config.getWhipLootMultiplier();
    boolean wasItemStolen = false;
    if (rand.nextFloat() < lootChance) {
      ItemStack loot =
          (lootable != null
              ? lootable.getEntityLoot(player, getType())
              : LootableEntityRegistry.getEntityLoot(target.getClass()));
      // TODO remove the following if Skulltulas are added:
      if (target instanceof EntitySpider && rand.nextInt(25) == 0) {
        loot = new ItemStack(ZSSItems.skulltulaToken);
      }
      if (loot != null) {
        EntityItem item = new EntityItem(worldObj, posX, posY + 1, posZ, loot);
        double dx = player.posX - posX;
        double dy = player.posY - posY;
        double dz = player.posZ - posZ;
        TargetUtils.setEntityHeading(item, dx, dy, dz, 1.0F, 1.0F, true);
        if (!worldObj.isRemote) {
          worldObj.spawnEntityInWorld(item);
        }
        player.triggerAchievement(ZSSAchievements.orcaThief);
        wasItemStolen = true;
      }
    }

    if (lootable == null || lootable.onLootStolen(player, wasItemStolen)) {
      if (!worldObj.isRemote) {
        target.getEntityData().setBoolean("LootableEntityFlag", true);
      }
    }
    return wasItemStolen;
  }
  @Override
  /** Called when the mob's health reaches 0. */
  public void onDeath(DamageSource cause) {
    super.onDeath(cause);

    if (cause.getSourceOfDamage() instanceof EntityArrow
        && cause.getEntity() instanceof EntityPlayer) {
      EntityPlayer entityplayer = (EntityPlayer) cause.getEntity();
      double d0 = entityplayer.posX - this.posX;
      double d1 = entityplayer.posZ - this.posZ;

      if (d0 * d0 + d1 * d1 >= 2500.0D) {
        entityplayer.triggerAchievement(AchievementList.snipeSkeleton);
      }
    } else if (cause.getEntity() instanceof EntityCreeper
        && ((EntityCreeper) cause.getEntity()).getPowered()
        && ((EntityCreeper) cause.getEntity()).isAIEnabled()) {
      ((EntityCreeper) cause.getEntity()).func_175493_co();
      this.entityDropItem(
          new ItemStack(ChaosBlock.itemChaoticWitherSkull, 1, !this.isEthereal ? 0 : 1), 0.0F);
    }
  }
  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (worldIn.isRemote) {
      return true;
    } else {
      TileEntity tileentity = worldIn.getTileEntity(pos);

      if (tileentity instanceof TileEntityBrewingStand) {
        playerIn.displayGUIChest((TileEntityBrewingStand) tileentity);
        playerIn.triggerAchievement(StatList.field_181729_M);
      }

      return true;
    }
  }
  private void getFoodPlate(
      World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) {
    int meta = par1World.getBlockMetadata(par2, par3, par4);

    TileTeppann tile = (TileTeppann) par1World.getTileEntity(par2, par3, par4);
    ItemStack getItem = new ItemStack(DCsAppleMilk.clam, 1, 2);
    if (tile != null) {
      getItem = this.getEjectFoods(meta);

      tile.getItemstack((ItemStack) null);
      if (!par5EntityPlayer.inventory.addItemStackToInventory(getItem)) {
        if (!par1World.isRemote) par5EntityPlayer.entityDropItem(getItem, 1.0F);
      }

      // 実績用処理
      if (getItem.getItem() == Item.getItemFromBlock(DCsAppleMilk.foodPlate)
          && getItem.getItemDamage() == 3) {
        par5EntityPlayer.triggerAchievement(AchievementRegister.getHamaguri);
      }

      tile.getItemstack((ItemStack) null);
      par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
    }
  }
  @Override
  public void runChoreAI() {
    owner.isFollowing = false;
    owner.isStaying = false;

    // Calculate interval based on the axe in the inventory.
    ItemStack axeStack = owner.inventory.getBestItemOfType(ItemAxe.class);

    if (owner instanceof EntityPlayerChild) {
      if (axeStack != null) {
        String itemName = axeStack.getItemName();

        if (itemName.contains("Wood")) {
          treeCutInterval = 40;
        } else if (itemName.contains("Stone")) {
          treeCutInterval = 30;
        } else if (itemName.contains("Iron")) {
          treeCutInterval = 25;
        } else if (itemName.contains("Diamond")) {
          treeCutInterval = 10;
        } else if (itemName.contains("Gold")) {
          treeCutInterval = 5;
        }

        // Unrecognized item type
        else {
          treeCutInterval = 25;
        }
      }

      // Fists
      else {
        treeCutInterval = 50;
      }
    }

    // A villager will cut with an iron axe.
    else {
      treeCutInterval = 25;
    }

    // Create a list to store coordinates containing wood.
    List<Coordinates> coordinatesContainingWood;

    // Check if a specific tree was selected.
    if (treeType != -1) {
      // Get only wood blocks whose metadata matches the tree type.
      coordinatesContainingWood =
          LogicHelper.getNearbyBlockCoordinatesWithMetadata(
              owner, Block.wood.blockID, treeType, 10);
    }

    // All trees should be cut.
    else {
      coordinatesContainingWood =
          LogicHelper.getNearbyBlockCoordinates(owner, Block.wood.blockID, 10);
    }

    // Check if they need some tree coordinates.
    if (!hasTreeCoordinates) {
      // Check that there's actually some in the list.
      if (coordinatesContainingWood.isEmpty()) {
        if (!owner.worldObj.isRemote) {
          if (!hasDoneWork) {
            owner.say(
                LanguageHelper.getString(
                    owner, "notify.child.chore.interrupted.woodcutting.notrees", false));
          } else {
            owner.say(
                LanguageHelper.getString(owner, "notify.child.chore.finished.woodcutting", false));
          }
        }

        endChore();
        return;
      } else {
        hasTreeCoordinates = true;

        Coordinates coordinatesOfBlock = null;
        Double distance = null;

        // Get the coordinates of the nearest valid wood block found of the specified ID.
        for (Coordinates coords : coordinatesContainingWood) {
          if (distance != null) {
            Double thisDistance =
                LogicHelper.getDistanceToXYZ(
                    owner.posX, owner.posY, owner.posZ, coords.x, coords.y, coords.z);

            if (thisDistance < distance) {
              coordinatesOfBlock = coords;
            }
          } else {
            if (owner.worldObj.getBlockId((int) coords.x, (int) coords.y - 1, (int) coords.z)
                    == Block.dirt.blockID
                || owner.worldObj.getBlockId((int) coords.x, (int) coords.y - 1, (int) coords.z)
                    == Block.grass.blockID) {
              distance =
                  LogicHelper.getDistanceToXYZ(
                      owner.posX, owner.posY, owner.posZ, coords.x, coords.y, coords.z);
              coordinatesOfBlock = coords;
            }
          }
        }

        if (coordinatesOfBlock != null) {
          treeCoordinatesX = coordinatesOfBlock.x;
          treeCoordinatesY = coordinatesOfBlock.y;
          treeCoordinatesZ = coordinatesOfBlock.z;

          // Calculate the lowest log.
          int distanceFromY = 0;

          while (distanceFromY != 10) {
            int blockId =
                owner.worldObj.getBlockId(
                    (int) treeCoordinatesX,
                    (int) treeCoordinatesY - distanceFromY,
                    (int) treeCoordinatesZ);

            if (blockId != Block.wood.blockID) {
              distanceFromY--;
              break;
            }

            distanceFromY++;
          }

          currentLogCoordinatesX = treeCoordinatesX;
          currentLogCoordinatesY = treeCoordinatesY - distanceFromY;
          currentLogCoordinatesZ = treeCoordinatesZ;
        }

        // A valid tree wasn't found.
        else {
          if (!owner.worldObj.isRemote) {
            owner.say(
                LanguageHelper.getString(
                    owner, "notify.child.chore.interrupted.woodcutting.notrees", false));
          }

          endChore();
          return;
        }
      }
    }

    // If they don't need tree coordinates, continue working.
    else {
      // Get the coordinates of all leaf blocks adjacent to the entity.
      List<Coordinates> leafBlockCoordinates =
          LogicHelper.getNearbyBlocksBottomTop(owner, Block.leaves.blockID, 1, 1);

      // Loop through each coordinate in the list and remove the leaves.
      for (Coordinates coords : leafBlockCoordinates) {
        owner.worldObj.setBlock((int) coords.x, (int) coords.y, (int) coords.z, 0);
      }

      // Check if they need to move to the tree to cut.
      if (!(owner.getDistance(treeCoordinatesX, owner.posY, treeCoordinatesZ) <= 2.5)) {
        // Set their path.
        AbstractEntity.faceCoordinates(owner, treeCoordinatesX, treeCoordinatesY, treeCoordinatesZ);

        if (!owner.worldObj.isRemote) {
          if (owner.getNavigator().noPath()) {
            owner
                .getNavigator()
                .setPath(
                    owner
                        .getNavigator()
                        .getPathToXYZ(treeCoordinatesX, treeCoordinatesY, treeCoordinatesZ),
                    0.3F);
          }
        }
      }

      // They don't need to move to the tree, so begin cutting.
      else {
        // Make sure the log they're going to cut exists, or the log above.
        if (owner.worldObj.getBlockId(
                    (int) currentLogCoordinatesX,
                    (int) currentLogCoordinatesY,
                    (int) currentLogCoordinatesZ)
                == Block.wood.blockID
            || owner.worldObj.getBlockId(
                    (int) currentLogCoordinatesX,
                    (int) currentLogCoordinatesY + 1,
                    (int) currentLogCoordinatesZ)
                == Block.wood.blockID) {
          // Check the ticks vs the interval to see if the log should be removed.
          if (treeCutTicks >= treeCutInterval) {
            treeCutTicks = 0;
            owner.damageHeldItem();

            ItemStack stackToAdd = new ItemStack(Block.wood, 1, treeType);
            stackToAdd.damageItem(treeType, owner);
            owner.inventory.addItemStackToInventory(stackToAdd);

            // Remove the block and increase Y by 1.
            if (!owner.worldObj.isRemote) {
              owner.worldObj.setBlock(
                  (int) currentLogCoordinatesX,
                  (int) currentLogCoordinatesY,
                  (int) currentLogCoordinatesZ,
                  0);
            }

            currentLogCoordinatesY++;

            // Remember they've done work.
            hasDoneWork = true;

            // Increment stat and check for achievement on children.
            if (owner instanceof EntityPlayerChild) {
              EntityPlayerChild child = (EntityPlayerChild) owner;

              child.woodChopped += 1;

              if (child.woodChopped >= 100) {
                EntityPlayer player = child.worldObj.getPlayerEntityByName(child.ownerPlayerName);

                if (player != null) {
                  player.triggerAchievement(MCA.instance.achievementChildWoodcut);
                }
              }
            }
          }

          // It's not time to remove the log, swing the axe and increment ticks.
          else {
            AbstractEntity.faceCoordinates(
                owner, currentLogCoordinatesX, currentLogCoordinatesY, currentLogCoordinatesZ);
            owner.swingItem();
            treeCutTicks++;
          }
        }

        // The log being cut doesn't exist. Get another one.
        else {
          hasTreeCoordinates = false;
        }
      }
    }
  }
Beispiel #25
0
  /**
   * Called frequently so the entity can update its state every tick as required. For example,
   * zombies and skeletons use this to react to sunlight and start to burn.
   */
  public void onLivingUpdate() {
    super.onLivingUpdate();
    this.worldObj.theProfiler.startSection("looting");

    if (!this.worldObj.isClient
        && this.canPickUpLoot()
        && !this.dead
        && this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing")) {
      List var1 =
          this.worldObj.getEntitiesWithinAABB(
              EntityItem.class, this.boundingBox.expand(1.0D, 0.0D, 1.0D));
      Iterator var2 = var1.iterator();

      while (var2.hasNext()) {
        EntityItem var3 = (EntityItem) var2.next();

        if (!var3.isDead && var3.getEntityItem() != null) {
          ItemStack var4 = var3.getEntityItem();
          int var5 = getArmorPosition(var4);

          if (var5 > -1) {
            boolean var6 = true;
            ItemStack var7 = this.getEquipmentInSlot(var5);

            if (var7 != null) {
              if (var5 == 0) {
                if (var4.getItem() instanceof ItemSword && !(var7.getItem() instanceof ItemSword)) {
                  var6 = true;
                } else if (var4.getItem() instanceof ItemSword
                    && var7.getItem() instanceof ItemSword) {
                  ItemSword var8 = (ItemSword) var4.getItem();
                  ItemSword var9 = (ItemSword) var7.getItem();

                  if (var8.func_150931_i() == var9.func_150931_i()) {
                    var6 =
                        var4.getItemDamage() > var7.getItemDamage()
                            || var4.hasTagCompound() && !var7.hasTagCompound();
                  } else {
                    var6 = var8.func_150931_i() > var9.func_150931_i();
                  }
                } else {
                  var6 = false;
                }
              } else if (var4.getItem() instanceof ItemArmor
                  && !(var7.getItem() instanceof ItemArmor)) {
                var6 = true;
              } else if (var4.getItem() instanceof ItemArmor
                  && var7.getItem() instanceof ItemArmor) {
                ItemArmor var11 = (ItemArmor) var4.getItem();
                ItemArmor var12 = (ItemArmor) var7.getItem();

                if (var11.damageReduceAmount == var12.damageReduceAmount) {
                  var6 =
                      var4.getItemDamage() > var7.getItemDamage()
                          || var4.hasTagCompound() && !var7.hasTagCompound();
                } else {
                  var6 = var11.damageReduceAmount > var12.damageReduceAmount;
                }
              } else {
                var6 = false;
              }
            }

            if (var6) {
              if (var7 != null && this.rand.nextFloat() - 0.1F < this.equipmentDropChances[var5]) {
                this.entityDropItem(var7, 0.0F);
              }

              if (var4.getItem() == Items.diamond && var3.func_145800_j() != null) {
                EntityPlayer var10 = this.worldObj.getPlayerEntityByName(var3.func_145800_j());

                if (var10 != null) {
                  var10.triggerAchievement(AchievementList.field_150966_x);
                }
              }

              this.setCurrentItemOrArmor(var5, var4);
              this.equipmentDropChances[var5] = 2.0F;
              this.persistenceRequired = true;
              this.onItemPickup(var3, 1);
              var3.setDead();
            }
          }
        }
      }
    }

    this.worldObj.theProfiler.endSection();
  }
  @Override
  protected void onImpact(MovingObjectPosition movingobjectposition) {
    for (int i = 0; i < 8; i++) {
      this.worldObj.spawnParticle("snowballpoof", posX, posY, posZ, 0.0D, 0.0D, 0.0D);
    }

    EntityPlayer player = (EntityPlayer) this.getThrower();

    if (!MeteorsMod.instance.isDimensionWhitelisted(worldObj.provider.dimensionId)) {
      if ((player != null) && (!this.worldObj.isRemote)) {
        player.addChatMessage(
            new ChatComponentText(StatCollector.translateToLocal("MeteorSummoner.wrongDimension")));
        if (!player.capabilities.isCreativeMode) {
          if (this.isRandom) {
            player.inventory.addItemStackToInventory(
                new ItemStack(MeteorItems.itemMeteorSummoner, 1));
          } else {
            player.inventory.addItemStackToInventory(
                new ItemStack(MeteorItems.itemMeteorSummoner, 1, this.mID + 1));
          }
        }
      }

      this.setDead();
      return;
    }

    if (!this.worldObj.isRemote) {

      boolean canHit = true;

      if (!worldObj.getGameRules().getGameRuleBooleanValue(HandlerWorld.SUMMON_METEORS_GAMERULE)) {
        canHit = false;
        player.addChatMessage(
            ClientHandler.createMessage(
                StatCollector.translateToLocal("MeteorSummoner.cannotSummon"),
                EnumChatFormatting.RED));
        if (!player.capabilities.isCreativeMode) {
          if (this.isRandom) {
            player.inventory.addItemStackToInventory(
                new ItemStack(MeteorItems.itemMeteorSummoner, 1));
          } else {
            player.inventory.addItemStackToInventory(
                new ItemStack(MeteorItems.itemMeteorSummoner, 1, this.mID + 1));
          }
        }
      } else if ((!MeteorsMod.instance.allowSummonedMeteorGrief) && (player != null)) {
        IMeteorShield shield =
            MeteorsMod.proxy
                .metHandlers
                .get(worldObj.provider.dimensionId)
                .getShieldManager()
                .getClosestShieldInRange((int) this.posX, (int) this.posZ);
        if (shield != null
            && (!player.getCommandSenderName().equalsIgnoreCase(shield.getOwner()))) {
          canHit = false;
          player.addChatMessage(
              new ChatComponentText(
                  StatCollector.translateToLocal("MeteorSummoner.landProtected")));
          if (!player.capabilities.isCreativeMode) {
            if (this.isRandom) {
              player.inventory.addItemStackToInventory(
                  new ItemStack(MeteorItems.itemMeteorSummoner, 1));
            } else {
              player.inventory.addItemStackToInventory(
                  new ItemStack(MeteorItems.itemMeteorSummoner, 1, this.mID + 1));
            }
          }
        }
      }

      if (canHit) {
        if (player != null) {
          player.addChatMessage(
              ClientHandler.createMessage(
                  StatCollector.translateToLocal("MeteorSummoner.incomingMeteor"),
                  EnumChatFormatting.LIGHT_PURPLE));
          player.triggerAchievement(HandlerAchievement.summonMeteor);
        }
        EntityMeteor meteorToSpawn =
            new EntityMeteor(
                this.worldObj,
                HandlerMeteor.getMeteorSize(),
                this.posX,
                this.posZ,
                EnumMeteor.getTypeFromID(this.mID),
                true);
        this.worldObj.spawnEntityInWorld(meteorToSpawn);
      }
    }
    this.setDead();
  }
 @Override
 public void harvestBlock(World w, EntityPlayer player, int x, int y, int z, int meta) {
   super.harvestBlock(w, player, x, y, z, meta);
   if (this == IceikaBlocks.frostedChest)
     player.triggerAchievement(DivineRPGAchievements.frozenGoods);
 }
Beispiel #28
0
 @Override
 public void onCreated(ItemStack stack, World world, EntityPlayer player) {
   if (this.hammerType.equals(EnumHammerType.CLAW))
     player.triggerAchievement(MinestuckAchievementHandler.getHammer);
 }
  public static void onCollideWithPlayer(
      EntityItem item, EntityPlayer par1EntityPlayer, boolean needsSneak) {
    if (ItemDummyContainer.customPickup && needsSneak && !par1EntityPlayer.isSneaking()) return;
    if (!item.worldObj.isRemote) {
      if (!ItemDummyContainer.customPickup && item.delayBeforeCanPickup > 0) {
        return;
      }

      EntityItemPickupEvent event = new EntityItemPickupEvent(par1EntityPlayer, item);

      if (MinecraftForge.EVENT_BUS.post(event)) {
        return;
      }

      ItemStack itemstack = item.getEntityItem();
      int i = itemstack.stackSize;

      if ((ItemDummyContainer.customPickup | item.delayBeforeCanPickup <= 0)
          && (item.func_145798_i() == null
              || item.lifespan - item.age <= 200
              || item.func_145798_i().equals(par1EntityPlayer.getCommandSenderName()))
          && (event.getResult() == Result.ALLOW
              || i <= 0
              || par1EntityPlayer.inventory.addItemStackToInventory(itemstack))) {
        if (itemstack.getItem() == Item.getItemFromBlock(Blocks.log)) {
          par1EntityPlayer.triggerAchievement(AchievementList.mineWood);
        }

        if (itemstack.getItem() == Item.getItemFromBlock(Blocks.log2)) {
          par1EntityPlayer.triggerAchievement(AchievementList.mineWood);
        }

        if (itemstack.getItem() == Items.leather) {
          par1EntityPlayer.triggerAchievement(AchievementList.killCow);
        }

        if (itemstack.getItem() == Items.diamond) {
          par1EntityPlayer.triggerAchievement(AchievementList.diamonds);
        }

        if (itemstack.getItem() == Items.blaze_rod) {
          par1EntityPlayer.triggerAchievement(AchievementList.blazeRod);
        }

        if (itemstack.getItem() == Items.diamond && item.func_145800_j() != null) {
          EntityPlayer entityplayer1 = item.worldObj.getPlayerEntityByName(item.func_145800_j());

          if (entityplayer1 != null && entityplayer1 != par1EntityPlayer) {
            entityplayer1.triggerAchievement(AchievementList.field_150966_x);
          }
        }

        FMLCommonHandler.instance().firePlayerItemPickupEvent(par1EntityPlayer, item);

        item.worldObj.playSoundAtEntity(
            par1EntityPlayer,
            "random.pop",
            0.2F,
            ((random.nextFloat() - random.nextFloat()) * 0.7F + 1.0F) * 2.0F);
        par1EntityPlayer.onItemPickup(item, i);

        if (itemstack.stackSize <= 0) {
          item.setDead();
        }
      }
    }
  }
  // 右クリック処理
  @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;
    }
  }