Package org.spout.vanilla.component.entity.inventory

Examples of org.spout.vanilla.component.entity.inventory.EntityInventory


    if (entity == null) {
      player.getEngine().getLogger().warning("EntityEquipmentHandler entity don't exist");
      return;
    }

    EntityInventory inventory = entity.get(EntityInventory.class);
    if (inventory == null) {
      player.getEngine().getLogger().warning("EntityEquipmentHandler entity haven't EntityInventory");
      return;
    }

    ItemStack item = message.get();

    switch (message.getSlot()) {
      case 0:
        inventory.getHeldItem().setMaterial(item.getMaterial());
        inventory.getHeldItem().setAmount(item.getAmount());
        return;
      case 1:
        inventory.getArmor().getHelmet().setMaterial(item.getMaterial());
        inventory.getArmor().getHelmet().setAmount(item.getAmount());
        return;
      case 2:
        inventory.getArmor().getChestPlate().setMaterial(item.getMaterial());
        inventory.getArmor().getChestPlate().setAmount(item.getAmount());
        return;
      case 3:
        inventory.getArmor().getLeggings().setMaterial(item.getMaterial());
        inventory.getArmor().getLeggings().setAmount(item.getAmount());
        return;
      case 4:
        inventory.getArmor().getBoots().setMaterial(item.getMaterial());
        inventory.getArmor().getBoots().setAmount(item.getAmount());
        return;
      default:
        player.getEngine().getLogger().warning("EntityEquipmentHandler slot bad value");
    }
  }
View Full Code Here


    for (Entity entity : nearbyEntities) {
      Item item = entity.get(Item.class);
      if (item == null) {
        continue;
      }
      EntityInventory inv = getOwner().get(EntityInventory.class);
      ArmorInventory armorInv = inv.getArmor();
      // Check if this item is equipable armor and has more protection than the currently equipped item
      boolean equip = false;
      if (item.getItemStack().getMaterial() instanceof Armor) {
        Armor armor = (Armor) item.getItemStack().getMaterial();
        for (int i = 0; i < armorInv.size(); i++) {
          if (armorInv.canSet(i, item.getItemStack())) {
            ItemStack slot = armorInv.get(i);
            if (slot == null || (slot.getMaterial() instanceof Armor && ((Armor) slot.getMaterial()).getBaseProtection() < armor.getBaseProtection())) {
              getOwner().getNetwork().callProtocolEvent(new EntityCollectItemEvent(getOwner(), entity));
              if (slot != null) {
                Item.drop(getOwner().getPhysics().getPosition(), slot, Vector3f.ZERO);
              }
              armorInv.set(i, item.getItemStack(), true);
              entity.remove();
              equip = true;
              break;
            }
          }
        }
      }
      // Check if this weapon deals more damage
      if (!equip && (item.getItemStack().getMaterial() instanceof VanillaItemMaterial || inv.getHeldItem() == null)) {
        if (inv.getHeldItem() == null) {
          equip = true;
        } else if (inv.getHeldItem().getMaterial() instanceof VanillaItemMaterial) {
          VanillaItemMaterial itemMaterial = (VanillaItemMaterial) item.getItemStack().getMaterial();
          VanillaItemMaterial equipMaterial = (VanillaItemMaterial) inv.getHeldItem().getMaterial();
          if (equipMaterial.getDamage() < itemMaterial.getDamage()) {
            equip = true;
          } else if (itemMaterial.getDamage() == equipMaterial.getDamage() && itemMaterial instanceof Tool && equipMaterial instanceof Tool
              && inv.getHeldItem().getData() > item.getItemStack().getData()) {
            equip = true;
          }
        }
        if (equip) {
          getOwner().getNetwork().callProtocolEvent(new EntityCollectItemEvent(getOwner(), entity));
          if (inv.getHeldItem() != null) {
            Item.drop(getOwner().getPhysics().getPosition(), inv.getHeldItem(), Vector3f.ZERO);
          }
          inv.getQuickbar().set(EntityQuickbarInventory.HELD_SLOT, item.getItemStack(), true);
          entity.remove();
          break;
        }
      }
    }
View Full Code Here

   * Drops all items from all Inventories of a Player.
   *
   * @param owner the entity.
   */
  private void dropInventoryItems(Entity owner) {
    EntityInventory inventory = owner.get(EntityInventory.class);
    if (inventory != null) {
      Set<ItemStack> toDrop = new HashSet<ItemStack>();
      for (Inventory inv : inventory.getDroppable()) {
        toDrop.addAll(inv);
      }
      org.spout.api.geo.discrete.Point position = owner.getPhysics().getPosition();
      for (ItemStack stack : toDrop) {
        if (stack != null) {
          Item.dropNaturally(position, stack);
        }
      }
      inventory.clear();
      inventory.updateAll();
    }
  }
View Full Code Here

    // Spawn message
    messages.add(new PlayerSpawnMessage(id, human.getName(), x, y, z, r, p, item, getSpawnParameters(entity)));

    // Armor
    EntityInventory inventory = entity.get(EntityInventory.class);
    final ItemStack boots, leggings, chestplate, helmet, held;
    if (inventory == null) {
      boots = leggings = chestplate = helmet = held = null;
    } else {
      final ArmorInventory armor = inventory.getArmor();
      boots = armor.getBoots();
      leggings = armor.getLeggings();
      chestplate = armor.getChestPlate();
      helmet = armor.getHelmet();
      held = inventory.getQuickbar().getSelectedSlot().get();
    }
    if (held != null) {
      messages.add(new EntityEquipmentMessage(entity.getId(), EntityEquipmentMessage.HELD_SLOT, held));
    }
    messages.add(new EntityEquipmentMessage(entity.getId(), EntityEquipmentMessage.BOOTS_SLOT, boots));
View Full Code Here

      parameters.add(new Parameter<Short>(Parameter.TYPE_SHORT, 1, (short) 1)); //Official expects some metadata to spawn
    }
    //TODO Headyaw

    messages.add(new EntityMobMessage(entityId, this.typeId, position, yaw, pitch, 0, (short) 0, (short) 0, (short) 0, parameters, rm));
    EntityInventory inventory = entity.get(EntityInventory.class);
    if (inventory != null) {
      final ItemStack held, boots, legs, chest, helm;
      held = inventory.getHeldItem();
      if (held != null) {
        messages.add(new EntityEquipmentMessage(entityId, EntityEquipmentMessage.HELD_SLOT, held));
      }
      boots = inventory.getArmor().getBoots();
      if (boots != null) {
        messages.add(new EntityEquipmentMessage(entityId, EntityEquipmentMessage.BOOTS_SLOT, boots));
      }
      legs = inventory.getArmor().getLeggings();
      if (legs != null) {
        messages.add(new EntityEquipmentMessage(entityId, EntityEquipmentMessage.LEGGINGS_SLOT, legs));
      }
      chest = inventory.getArmor().getChestPlate();
      if (chest != null) {
        messages.add(new EntityEquipmentMessage(entityId, EntityEquipmentMessage.CHESTPLATE_SLOT, chest));
      }
      helm = inventory.getArmor().getHelmet();
      if (helm != null) {
        messages.add(new EntityEquipmentMessage(entityId, EntityEquipmentMessage.HELMET_SLOT, helm));
      }
    }
    return messages;
View Full Code Here

TOP

Related Classes of org.spout.vanilla.component.entity.inventory.EntityInventory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.