Package org.spout.api.inventory

Examples of org.spout.api.inventory.ItemStack


    getDrops().EXPLOSION.add(VanillaMaterials.COAL);
  }

  @Override
  public ItemStack getResult() {
    return new ItemStack(VanillaMaterials.COAL, 1);
  }
View Full Code Here


    this.addMiningType(ToolType.SPADE);
  }

  @Override
  public ItemStack getResult() {
    return new ItemStack(VanillaMaterials.GLASS, 1);
  }
View Full Code Here

  }

  @Override
  public WindowCreativeActionMessage decode(ByteBuf buffer) throws IOException {
    short slot = buffer.readShort();
    ItemStack item = VanillaByteBufUtils.readItemStack(buffer);
    return new WindowCreativeActionMessage(slot, item);
  }
View Full Code Here

  public boolean shootItem(Block block, Slot slot) {
    if (slot == null) {
      GeneralEffects.RANDOM_CLICK2.playGlobal(block.getPosition());
      return false;
    }
    ItemStack item = slot.get();
    Block facingBlock = block.translate(this.getFacing(block));
    if (item.getMaterial().equals(VanillaMaterials.TNT)) {
      //Place Activated TNT entity at direction of Dispenser
      if (facingBlock.getMaterial().getShape() != null) {
        World world = facingBlock.getWorld();
        Tnt tnt = world.createEntity(facingBlock.getPosition(), Tnt.class).add(Tnt.class);
        tnt.getOwner().getPhysics().force(new Vector3f(0.5D, 0.5D, 0.5D));
        world.spawnEntity(tnt.getOwner());
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof SpawnEgg) {
      if (facingBlock.getMaterial().getShape() != null) {
        Entity entity = facingBlock.getWorld().createEntity(facingBlock.getPosition(), ((SpawnEgg) item.getMaterial()).getSpawnedComponent());
        entity.getPhysics().translate(new Vector3f(0.5D, 0.5D, 0.5D));
        facingBlock.getWorld().spawnEntity(entity);
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof FullBucket) {
      //Attempt to place any FullBucket with it's placement material
      if (facingBlock.getMaterial().getShape() != null) {
        facingBlock.setMaterial(((FullBucket) item.getMaterial()).getPlacedMaterial());
        item.setMaterial(VanillaMaterials.BUCKET);
        //TODO: update physics properly after block has been changed to the liquid
        return true;
      }
    } else if (item.getMaterial().equals(VanillaMaterials.FLINT_AND_STEEL)) {
      if (facingBlock.getMaterial().equals(VanillaMaterials.TNT)) {
        // Detonate TntBlock
        VanillaMaterials.TNT.onIgnite(block, new BlockCause(block));
        slot.addData(1);
        return true;
      } else {
        // Default fire placement
        if (VanillaMaterials.FIRE.canCreate(facingBlock, (short) 0, new BlockCause(block))) {
          VanillaMaterials.FIRE.onCreate(facingBlock, (short) 0, new BlockCause(block));
          slot.addData(1);
          return true;
        }
      }
    } else if (item.getMaterial().equals(VanillaMaterials.BUCKET)) {
      if (facingBlock.getMaterial() instanceof Liquid) {
        Liquid liquid = (Liquid) facingBlock.getMaterial();
        if (liquid.isSource(facingBlock)) {
          item.setMaterial(liquid.getContainerMaterial());
          facingBlock.setMaterial(VanillaMaterials.AIR);
          //TODO: physics update necessary here
          return true;
        }
      }
    } else if (item.getMaterial() instanceof Armor) {
      for (Player player : block.getWorld().getNearbyPlayers(block.getPosition(), 2)) {
        if (player.getPhysics().getPosition().getBlock().equals(facingBlock)) {
          PlayerInventory inv = player.get(PlayerInventory.class);
          int armorSlot = ((Armor) item.getMaterial()).getEquipableSlot();
          if (inv.getArmor().get(armorSlot) != null) {
            return false;
          }
          boolean canSet = inv.getArmor().canSet(armorSlot, item);
          InventoryCanSetEvent event = player.getEngine().getEventManager().callEvent(new InventoryCanSetEvent(inv.getArmor(), new BlockCause(block), armorSlot, item, !canSet));
          if (event.isCancelled()) {
            return false;
          }
          inv.getArmor().set(armorSlot, item, true);
          slot.addAmount(-1);
          return true;
        }
      }
    } else if (item.getMaterial().equals(Dye.BONE_MEAL)) {
      if (facingBlock.getMaterial() instanceof Growing && ((Growing) facingBlock.getMaterial()).grow(facingBlock, Dye.BONE_MEAL)) {
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof MinecartItem) {
      if (facingBlock.getMaterial() instanceof RailBase) {
        MinecartItem<?> mineItem = (MinecartItem<?>) item.getMaterial();
        mineItem.spawnEntity(facingBlock, Vector3f.ZERO);
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof BoatItem) {
      Point placePos;
      if (facingBlock.getMaterial() instanceof Water) {
        placePos = facingBlock.getPosition().add(.5f, 1f, .5f);
      } else if (facingBlock.getMaterial().equals(VanillaMaterials.AIR) && facingBlock.translate(BlockFace.BOTTOM).getMaterial() instanceof Water) {
        placePos = facingBlock.getPosition().add(.5f, 0f, .5f);
      } else {
        return false;
      }
      Boat boat = ((BoatItem) item.getMaterial()).spawnEntity(placePos);
      block.getWorld().spawnEntity(boat.getOwner());
      slot.addAmount(-1);
      return true;
    } else {
      // Try to shoot the item selected if we can't do anything else with it
      final Random rand = GenericMath.getRandom();
      Vector3f direction = this.getFacing(block).getOffset();

      // Calculate position to shoot from
      Point position = block.getPosition().add(direction.mul(0.6));
      VanillaEntityComponent toLaunch = null;

      // Calculate shooting velocity using facing direction
      Vector3f velocity = direction.mul(rand.nextDouble() * 0.1 + 0.2);
      // Set velocity y to above (0.2)
      velocity = velocity.mul(1.0, 0.0, 1.0).add(0.0, 0.2, 0.0);
      velocity = velocity.add(0.045 * rand.nextGaussian(), 0.045 * rand.nextGaussian(), 0.045 * rand.nextGaussian());

      Effect shootEffect;
      Material material = item.getMaterial();
      //TODO: Implement the following 'special' shoot cases:
      // - eggs, arrows, fireballs and snowballs
      // - potions, exp. bottles, monster eggs
      // - armor,

View Full Code Here

            break;
        }
      }
      slot.addAmount(-1);
      if (slot.get().getMaterial().equals(VanillaMaterials.MUSHROOM_STEW)) {
        slot.add(new ItemStack(VanillaMaterials.BOWL, 1));
      }
    }
  }
View Full Code Here

    return 25;
  }

  @Override
  public ItemStack getResult() {
    return new ItemStack(Coal.CHARCOAL, 1);
  }
View Full Code Here

        }
      }

      Slot slot = PlayerUtil.getHeldSlot(entity);
      if (slot != null) {
        ItemStack fullbottle = new ItemStack(PotionItem.WATER_BOTTLE, 1);
        entity.get(PlayerInventory.class).getQuickbar().add(fullbottle);
        if (!fullbottle.isEmpty()) {
          entity.get(PlayerInventory.class).getMain().add(fullbottle);
        }
        if (fullbottle.isEmpty() && !PlayerUtil.isCostSuppressed(entity)) {
          slot.addAmount(-1);
        }
      }
    }
  }
View Full Code Here

      if (sheep.isSheared()) {
        //TODO: Also return if this is a baby sheep
        return;
      }
      short col = sheep.getColor().getData();
      ItemStack itemStack = new ItemStack(VanillaMaterials.WOOL, col, GenericMath.getRandom().nextInt(3) + 1);

      SheepShearedEvent event = VanillaPlugin.getInstance().getEngine().getEventManager().callEvent(new SheepShearedEvent(other, entity, itemStack));

      if (event.isCancelled()) {
        return;
View Full Code Here

    if (this.effect != null) {
      entity.add(Effects.class).add(new EntityEffect(effect, this.getTier(), this.getTime()));
    }

    slot.addAmount(-1);
    entity.get(PlayerInventory.class).getMain().add(new ItemStack(VanillaMaterials.GLASS_BOTTLE, 1));
  }
View Full Code Here

    }
    Slot currentSlot = PlayerUtil.getHeldSlot(player);
    if (currentSlot == null) {
      return;
    }
    ItemStack heldItem = currentSlot.get();

    // Don't block protections if dropping an item, silly Notch...
    if (state != PlayerDiggingMessage.STATE_DROP_ITEM && state != PlayerDiggingMessage.STATE_SHOOT_ARROW_EAT_FOOD) {
      Collection<Protection> protections = player.getEngine().getServiceManager().getRegistration(ProtectionService.class).getProvider().getAllProtections(point);
      for (Protection p : protections) {
        if (p.contains(point) && !human.isOp()) {
          player.getNetwork().getSession().send(new BlockChangeMessage(x, y, z, minecraftID, block.getBlockData() & 0xF, rm));
          player.sendMessage(ChatStyle.DARK_RED + "This area is a protected spawn point!");
          return;
        }
      }
    }

    if (state == PlayerDiggingMessage.STATE_DROP_ITEM && x == 0 && y == 0 && z == 0) {
      human.dropItem();
      return;
    }

    boolean isInteractable = true;
    if (blockMaterial == VanillaMaterials.AIR) {
      isInteractable = false;
    }
    // TODO VanillaPlayerInteractBlockEvent and add in Results to it (to
    // more indepthly take away durability).
    switch (state) {
      case PlayerDiggingMessage.STATE_START_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          final PlayerInteractBlockEvent event = new PlayerInteractBlockEvent(player, block, point, clickedFace, Action.LEFT_CLICK);
          if (player.getEngine().getEventManager().callEvent(event).isCancelled()) {
            if (human.isCreative() || blockMaterial.getHardness() == 0.0f) {
              session.send(new BlockChangeMessage(block, player.getNetwork().getRepositionManager()));
              Sign sign = block.get(Sign.class);
              if (sign != null) {
                session.send(new SignMessage(block.getX(), block.getY(), block.getZ(), sign.getText(), player.getNetwork().getRepositionManager()));
              }
            }
          } else {
            // Perform interactions
            if (heldItem == null) {
              // interacting using fist
            } else if (!isInteractable) {
              // interacting with nothing using item
              heldItem.getMaterial().onInteract(player, Action.LEFT_CLICK);
            } else {
              // interacting with block using item
              heldItem.getMaterial().onInteract(player, block, Action.LEFT_CLICK, clickedFace);
            }

            if (isInteractable) {
              Block neigh = block.translate(clickedFace);
              boolean fire = neigh.getMaterial().equals(VanillaMaterials.FIRE);
              if (fire) {
                // put out fire
                if (VanillaMaterials.FIRE.onDestroy(neigh, new PlayerBreakCause(player, neigh))) {
                  GeneralEffects.RANDOM_FIZZ.playGlobal(block.getPosition());
                }
              } else if (human.isSurvival() && blockMaterial.getHardness() != 0.0f) {
                ItemStack currentItem = PlayerUtil.getHeldSlot(player).get();
                if (currentItem != null) {
                  player.get(Digging.class).startDigging(new Point(w, x, y, z), currentItem.getMaterial());
                } else {
                  player.get(Digging.class).startDigging(new Point(w, x, y, z), VanillaMaterials.AIR);
                }
              } else {
                // insta-break
View Full Code Here

TOP

Related Classes of org.spout.api.inventory.ItemStack

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.