Package org.spout.vanilla.event.entity.network

Examples of org.spout.vanilla.event.entity.network.EntityCollectItemEvent


        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();
View Full Code Here


  @Override
  public void onTick(float dt) {
    for (Entity entity : getNearbyEntities()) {
      Item item = entity.get(Item.class);
      if (item != null && item.canBeCollected()) {
        getOwner().getNetwork().callProtocolEvent(new EntityCollectItemEvent(getOwner(), entity));
        PlayerInventory inv = getOwner().get(PlayerInventory.class);
        if (inv != null) {
          inv.add(item.getItemStack());
        }
        entity.remove();
View Full Code Here

TOP

Related Classes of org.spout.vanilla.event.entity.network.EntityCollectItemEvent

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.