Exemple #1
0
  @Override
  public boolean itemInteractionForEntity(
      ItemStack item, EntityPlayer player, EntityLivingBase entity) {

    if (entity.worldObj.isRemote) {
      return false;
    }
    boolean isCreative = player != null && player.capabilities.isCreativeMode;
    if (containsSoul(item) && !isCreative) {
      return false;
    }
    if (entity instanceof EntityPlayer) {
      return false;
    }

    String entityId = EntityList.getEntityString(entity);
    if (isBlackListed(entityId)) {
      return false;
    }

    if (!Config.soulVesselCapturesBosses && entity instanceof IBossDisplayData) {
      return false;
    }

    NBTTagCompound root = new NBTTagCompound();
    root.setString("id", entityId);
    entity.writeToNBT(root);

    ItemStack capturedMobVessel = new ItemStack(EnderIO.itemSoulVessel);
    capturedMobVessel.setTagCompound(root);
    setDisplayNameFromEntityNameTag(capturedMobVessel, entity);

    player.swingItem();
    if (!isCreative) {
      entity.setDead();
      if (entity.isDead) {
        item.stackSize--;
        if (!player.inventory.addItemStackToInventory(capturedMobVessel)) {
          entity.worldObj.spawnEntityInWorld(
              new EntityItem(
                  entity.worldObj, entity.posX, entity.posY, entity.posZ, capturedMobVessel));
        }
        player.setCurrentItemOrArmor(0, item);
        ((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer);
        return true;
      }
    } else {
      if (!player.inventory.addItemStackToInventory(
          capturedMobVessel)) // Inventory full, drop it in the world!
      {
        entity.worldObj.spawnEntityInWorld(
            new EntityItem(
                entity.worldObj, entity.posX, entity.posY, entity.posZ, capturedMobVessel));
      }
      ((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer);
      return true;
    }
    return false;
  }
 /** sends the players inventory to himself */
 public void syncPlayerInventory(EntityPlayerMP playerIn) {
   playerIn.sendContainerToPlayer(playerIn.inventoryContainer);
   playerIn.setPlayerHealthUpdated();
   playerIn.playerNetServerHandler.sendPacket(
       new S09PacketHeldItemChange(playerIn.inventory.currentItem));
 }
 /** sends the players inventory to himself */
 public void syncPlayerInventory(EntityPlayerMP par1EntityPlayerMP) {
   par1EntityPlayerMP.sendContainerToPlayer(par1EntityPlayerMP.inventoryContainer);
   par1EntityPlayerMP.setPlayerHealthUpdated();
   par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(
       new Packet16BlockItemSwitch(par1EntityPlayerMP.inventory.currentItem));
 }