Package org.spout.api.material

Examples of org.spout.api.material.Material


    getOwner().add(MetadataComponent.class).addMeta(new Metadata<ItemStack>(Metadata.TYPE_ITEM, 2) {
      private ItemStack lastItem = null;

      @Override
      public ItemStack getValue() {
        Material mat = getMaterial();
        if (mat == null) {
          return null;
        }
        // Re-use last item to avoid the creation of too many items
        // If material changes, create a new item to break the reference
View Full Code Here


          break;
        }
      }

      // Validate the clicked material to see if it can be picked up
      final Material filled; // material to fill the bucket with
      if (block.getMaterial() instanceof Water && VanillaMaterials.WATER.isSource(block)) {
        filled = VanillaMaterials.WATER_BUCKET;
      } else if (block.getMaterial() instanceof Lava && VanillaMaterials.LAVA.isSource(block)) {
        filled = VanillaMaterials.LAVA_BUCKET;
      } else {
View Full Code Here

    for (String key : recipesNode.getKeys(false)) {
      ConfigurationNode recipe = recipesNode.getNode(key);
      RecipeBuilder builder = new RecipeBuilder();
      builder.setIncludeData(recipe.getNode("includedata") != null && recipe.getNode("includedata").getBoolean());
      String[] resultString = recipe.getNode("result").getString().split(",");
      Material matched = MaterialRegistry.get(resultString[0]);
      if (matched == null) {
        Spout.getLogger().log(Level.WARNING, "Unknown material result for {1}: {0}", new Object[] {resultString[0], key});
        continue;
      }
      int amount;
      try {
        amount = Integer.parseInt(resultString[1]);
      } catch (NumberFormatException numberFormatException) {
        Spout.getLogger().log(Level.WARNING, "Unknown number for {1}: {0}", new Object[] {resultString[1], key});
        amount = 1;
      } catch (IndexOutOfBoundsException ex) {
        Spout.getLogger().log(Level.WARNING, "Wrong number of parts for {1}: {0} should have a \",<amount>\" at the end of it.", new Object[] {recipe.getNode("result").getString(), key});
        amount = 1;
      }
      builder.setResult(matched, amount);
      if (recipe.getNode("type").getString().equalsIgnoreCase("Shaped")) {
        for (String inKey : recipe.getNode("ingredients").getKeys(false)) {
          Material ingredient = MaterialRegistry.get(recipe.getNode("ingredients").getNode(inKey).getString());
          if (ingredient == null) {
            Spout.getLogger().log(Level.WARNING, "Unknown material ingredient for {1}: {0}", new Object[] {recipe.getNode("ingredients").getNode(inKey).getString(), key});
            continue;
          }
          builder.setIngredient(inKey.charAt(0), ingredient);
        }
        for (Iterator<String> it = recipe.getNode("rows").getStringList().iterator(); it.hasNext(); ) {
          String row = it.next();
          List<Character> rowChars = new ArrayList<Character>();
          for (char c : row.toCharArray()) {
            rowChars.add(c);
          }
          builder.addRow(rowChars);
        }
        try {
          recipes.put(key, builder.buildShapedRecipe());
        } catch (IllegalStateException ex) {
          Spout.getLogger().log(Level.WARNING, "Error when adding recipe {0} because: {1}", new Object[] {key, ex.getMessage()});
        }
      } else if (recipe.getNode("type").getString().equalsIgnoreCase("Shapeless")) {
        for (String rowString : recipe.getNode("ingredients").getStringList(new ArrayList<String>())) {
          Material ingredient = MaterialRegistry.get(rowString);
          if (ingredient == null) {
            Spout.getLogger().log(Level.WARNING, "Unknown material ingredient for {1}: {0}", new Object[] {rowString, key});
            continue;
          }
          builder.addIngredient(ingredient);
        }
        try {
          recipes.put(key, builder.buildShapelessRecipe());
        } catch (IllegalStateException ex) {
          Spout.getLogger().log(Level.WARNING, "Error when adding recipe {0} because: {1}", new Object[] {key, ex.getMessage()});
        }
      } else if (recipe.getNode("type").getString().equalsIgnoreCase("Smelted")) {
        for (String rowString : recipe.getNode("ingredients").getStringList(new ArrayList<String>())) {
          Material ingredient = MaterialRegistry.get(rowString);
          if (ingredient == null) {
            Spout.getLogger().log(Level.WARNING, "Unknown material ingredient for {1}: {0}", new Object[] {recipe.getNode("ingredients").getNode(rowString).getString(), key});
            continue;
          }
          builder.addIngredient(ingredient);
View Full Code Here

        }
      } else if (Substance.class.isAssignableFrom(clazz)) {
        final Substance substance = entity.get(Substance.class);
        switch (ObjectType.valueOf(name.toUpperCase())) {
          case ITEM:
            Material item = VanillaArgumentTypes.popMaterial("item", args);
            ((Item) substance).setItemStack(new ItemStack(item, 1));
            break;
          case FALLING_OBJECT:
            Material block = VanillaArgumentTypes.popMaterial("block", args);
            if (!(block instanceof BlockMaterial)) {
              throw new CommandException("Material " + block.getDisplayName() + " is not a block!");
            }
            ((FallingBlock) substance).setMaterial((BlockMaterial) block);
            break;
        }
      }
View Full Code Here

  @Override
  public boolean onShiftClick(ItemStack item, int slot, Inventory from) {
    if (!(from instanceof BrewingStandInventory)) {
      final BrewingStandInventory inventory = getBrewingStand().getInventory();
      Material material = item.getMaterial();
      if (material instanceof PotionItem) {
        // Put into output slots
        for (int i = 0; i < 3; i++) {
          if (inventory.getOutput(i) == null) {
            inventory.set(i, item);
View Full Code Here

  @CommandDescription (aliases = "clear", usage = "[player] [item] [data]", desc = "Clears the target's inventory")
  @Permissible ("vanilla.command.clear")
  public void clear(CommandSource source, CommandArguments args) throws CommandException {
    Player player = args.popPlayerOrMe("player", source);
    Material filter = VanillaArgumentTypes.popMaterial("filter", args);
    Integer data = args.popInteger("data");
    args.assertCompletelyParsed();

    PlayerInventory inv = player.get(PlayerInventory.class);
    if (inv == null) {
View Full Code Here

    if (args.length() != 1) {
      player = args.popPlayerOrMe("player", source);
    } else {
      player = args.checkPlayer(source);
    }
    Material material = VanillaArgumentTypes.popMaterial("material", args);
    int quantity = args.popInteger("quantity");
    int data = args.popInteger("data");
    args.assertCompletelyParsed();

    PlayerInventory inventory = player.get(PlayerInventory.class);
    if (inventory != null) {
      inventory.add(new ItemStack(material, data, quantity));
      source.sendMessage(plugin.getPrefix() + ChatStyle.GREEN + "Gave "
          + ChatStyle.WHITE + player.getName() + " " + quantity + ChatStyle.GREEN + " of " + ChatStyle.WHITE
          + material.getDisplayName());
    } else {
      throw new CommandException(player.getName() + " doesn't have a inventory!");
    }
  }
View Full Code Here

  @Override
  public boolean onShiftClick(ItemStack stack, int slot, Inventory from) {
    if (!(from instanceof FurnaceInventory)) {
      final FurnaceInventory furnace = this.getFurnace().getInventory();
      Material material = stack.getMaterial();
      // Try to put the item into the furnace, fuel first (!)
      if (material instanceof Fuel && ((Fuel) material).getFuelTime() > 0.0f) {
        // Put into fuel slot
        furnace.getFuelSlot().add(stack);
        from.set(slot, stack);
View Full Code Here

    Slot held = PlayerUtil.getHeldSlot(playerEnt);
    if (held == null) {
      return;
    }
    ItemStack holding = held.get();
    Material holdingMat = holding == null ? VanillaMaterials.AIR : holding.getMaterial();
    if (holdingMat == null) {
      holdingMat = VanillaMaterials.AIR;
    }
    //TODO VanillaPlayerInteractEntityEvent maybe?
    PlayerInteractEntityEvent event;

    if (message.isPunching()) {
      event = new PlayerInteractEntityEvent(playerEnt, clickedEntity, clickedEntity.getPhysics().getPosition(), Action.LEFT_CLICK);
      if (Spout.getEventManager().callEvent(event).isCancelled()) {
        return;
      }
      holdingMat.onInteract(playerEnt, clickedEntity, Action.LEFT_CLICK);
      clickedEntity.interact(event);

      if (clickedEntity.get(Human.class) != null && !VanillaConfiguration.PLAYER_PVP_ENABLED.getBoolean()) {
        return;
      }

      Living clicked = clickedEntity.get(Living.class);
      if (clicked != null) {
        //TODO: Reimplement exhaustion values

        int damage = 1;
        if (holding != null && holdingMat instanceof VanillaMaterial) {
          damage = ((VanillaMaterial) holdingMat).getDamage();
          if (holdingMat instanceof Tool) {
            // This is a bit of a hack due to the way Tool hierarchy is now (Only Swords can have a damage modifier, but Sword must be an interface and therefore is not able to contain getDamageModifier without code duplication)
            damage += ((Tool) holdingMat).getDamageBonus(clickedEntity, holding);
            //            player.getInventory().getQuickbar().getCurrentSlotInventory().addData(1); TODO: Reimplement durability change
          }
        }

        //Potion modification
        if (holdingMat.equals(VanillaMaterials.AIR)) {
          Effects effect = playerEnt.add(Effects.class);
          if (effect.contains(EntityEffectType.STRENGTH)) {
            damage += 3;
          }
          if (effect.contains(EntityEffectType.WEAKNESS)) {
            damage -= 2;
          }
        }
        //END Potion modification

        // Damage the clicked entity
        if (damage > 0 && !PlayerUtil.isCreativePlayer(clickedEntity) && !clicked.getHealth().isDead()) {
          clicked.getHealth().damage(damage, new PlayerDamageCause(playerEnt, DamageType.ATTACK), damage > 0);
        }
      }
    } else {
      event = new PlayerInteractEntityEvent(playerEnt, clickedEntity, clickedEntity.getPhysics().getPosition(), Action.LEFT_CLICK);
      if (Spout.getEventManager().callEvent(event).isCancelled()) {
        return;
      }
      holdingMat.onInteract(playerEnt, clickedEntity, Action.RIGHT_CLICK);
      clickedEntity.interact(event);
    }
  }
View Full Code Here

    Slot currentSlot = PlayerUtil.getHeldSlot(player);
    if (currentSlot == null) {
      return;
    }
    ItemStack holding = currentSlot.get();
    Material holdingMat = holding == null ? null : holding.getMaterial();

    /*
     * The notch client's packet sending is weird. Here's how it works: If the client is clicking a block not in range, sends a packet with x=-1,y=255,z=-1 If the client is clicking a block in
     * range with an item in hand (id > 255) Sends both the normal block placement packet and a (-1,255,-1) one If the client is placing a block in range with a block in hand, only one normal
     * packet is sent That is how it usually happens. Sometimes it doesn't happen like that. Therefore, a hacky workaround.
     */
    final BlockFace clickedFace = message.getDirection();
    Hunger hunger = player.add(Hunger.class);
    if ((holdingMat instanceof Food && hunger.getHunger() != VanillaData.HUNGER.getDefaultValue()) || holdingMat instanceof Sword || (holdingMat instanceof PotionItem && !((PotionItem) holdingMat).isSplash())) {
      player.get(Living.class).setEatingBlocking(true);
      hunger.setEating(true, currentSlot);
      return;
    }
    if (clickedFace == BlockFace.THIS) {
      // Right clicked air with an item.
      PlayerInteractBlockEvent event = Spout.getEventManager().callEvent(new PlayerInteractBlockEvent(player, null, null, clickedFace, Action.RIGHT_CLICK));

      // May have been changed by the event
      holding = currentSlot.get();
      holdingMat = holding == null ? null : holding.getMaterial();

      if (holdingMat != null) {
        holdingMat.onInteract(player, Action.RIGHT_CLICK);
      }
    } else {
      // TODO: Validate the x/y/z coordinates of the message to check if it is in range of the player
      // This is an anti-hack requirement (else hackers can load far-away chunks and crash the server)

      // Get clicked block and validated face against it was placed
      final Block clickedBlock = world.getBlock(message.getX(), message.getY(), message.getZ());
      final BlockMaterial clickedMaterial = clickedBlock.getMaterial();

      // Perform interaction event
      PlayerInteractBlockEvent interactEvent = Spout.getEventManager().callEvent(new PlayerInteractBlockEvent(player, clickedBlock, clickedBlock.getPosition(), clickedFace, Action.RIGHT_CLICK));

      // May have been changed by the event
      holding = currentSlot.get();
      holdingMat = holding == null ? null : holding.getMaterial();

      // check if the interaction was cancelled by the event
      if (interactEvent.isCancelled()) {
        refreshClient(player, clickedBlock, clickedFace, rm);
        return;
      }
      if (holdingMat != null) {
        holdingMat.onInteract(player, clickedBlock, Action.RIGHT_CLICK, clickedFace);
      }
      clickedMaterial.onInteract(player, clickedBlock, Action.RIGHT_CLICK, clickedFace);

      // If the holding material can be placed, place it
      if (holdingMat instanceof Placeable) {
View Full Code Here

TOP

Related Classes of org.spout.api.material.Material

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.