コード例 #1
0
  @SubscribeEvent
  public void onPlayerDrops(PlayerDropsEvent event) {
    Iterator<EntityItem> iterator = event.drops.iterator();
    while (iterator.hasNext()) {
      EntityItem entItem = iterator.next();
      ItemStack is = entItem.getEntityItem();

      if ((is != null) && (is.getItem() instanceof ItemEnderGlove)) {
        is.damageItem(2, event.entityPlayer);
        InventoryUtils.addItemStackToInventory(
            InventoryUtils.getPlayerEnderChest(event.entityPlayer), is);
        PlayerUtils.sendMessage(
            event.entityPlayer,
            EnumChatFormatting.DARK_PURPLE
                + is.getDisplayName()
                + " was succesfully saved to your Ender Chest!");
        boilerplate.common.utils.Utils.playSFX(
            event.entityPlayer.worldObj,
            (int) entItem.prevPosX,
            (int) entItem.prevPosY,
            (int) entItem.prevPosZ,
            "mob.endermen.portal");
        entItem.setDead();
      }
    }
  }
コード例 #2
0
  @SubscribeEvent
  public void onLivingDrops(LivingDropsEvent event) {
    if (InitConfig.extraBlockDrops) {
      if (event.entityLiving instanceof EntityAnimal) {
        event.drops.add(
            new EntityItem(
                event.entityLiving.worldObj,
                event.entityLiving.posX,
                event.entityLiving.posY,
                event.entityLiving.posZ,
                new ItemStack(Items.bone, this.rand.nextInt(3) * event.lootingLevel, 1)));
      } else if (event.entityLiving instanceof EntityCreeper) {
        if (this.rand.nextInt(50) > 5) {
          event.drops.add(
              new EntityItem(
                  event.entityLiving.worldObj,
                  event.entityLiving.posX,
                  event.entityLiving.posY,
                  event.entityLiving.posZ,
                  new ItemStack(Blocks.tnt, this.rand.nextInt(1) + event.lootingLevel, 1)));
        }
      } else if (event.entityLiving instanceof EntityEnderman) {
        EntityEnderman enderman = (EntityEnderman) event.entityLiving;
        event.drops.add(
            new EntityItem(
                event.entityLiving.worldObj,
                event.entityLiving.posX,
                event.entityLiving.posY,
                event.entityLiving.posZ,
                enderman.getHeldItem()));
      }
    } else if ((event.entityLiving instanceof EntityDragon) && InitConfig.dragonDrop) {
      event.entityLiving.dropItem(InitItems.itemEnderGlove, 1);
    }
    if (event.source.getEntity() instanceof EntityPlayer) {
      EntityPlayer player = (EntityPlayer) event.source.getEntity();
      Iterator<EntityItem> iterator = event.drops.iterator();
      while (iterator.hasNext()) {
        EntityItem entItem = iterator.next();
        ItemStack is = entItem.getEntityItem();

        if (is != null) {
          InventoryUtils.addItemStackToInventory(InventoryUtils.getPlayerEnderChest(player), is);
          entItem.setDead();
        }
      }
    }
  }