Exemplo n.º 1
0
  // returns an Potion item with cooked ingredients
  public ItemStack cook(int state) {

    ItemStack potion = new ItemStack(Material.POTION);
    PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();

    // cookedTime is always time in minutes, state may differ with number of ticks
    cookedTime = state;
    String cookedName = null;
    BRecipe cookRecipe = getCookRecipe();

    int uid = Brew.generateUID();

    if (cookRecipe != null) {
      // Potion is best with cooking only
      int quality =
          (int)
              Math.round(
                  (getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
      P.p.debugLog("cooked potion has Quality: " + quality);
      Brew brew = new Brew(uid, quality, cookRecipe, this);
      Brew.addOrReplaceEffects(potionMeta, brew.getEffects());

      cookedName = cookRecipe.getName(quality);
      potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));

    } else {
      // new base potion
      new Brew(uid, this);

      if (state <= 1) {
        cookedName = P.p.languageReader.get("Brew_ThickBrew");
        potion.setDurability(Brew.PotionColor.BLUE.getColorId(false));
      } else {
        for (Material ingredient : ingredients.keySet()) {
          if (cookedNames.containsKey(ingredient)) {
            // if more than half of the ingredients is of one kind
            if (ingredients.get(ingredient) > (getIngredientsCount() / 2)) {
              cookedName = cookedNames.get(ingredient);
              potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
            }
          }
        }
      }
    }
    if (cookedName == null) {
      // if no name could be found
      cookedName = P.p.languageReader.get("Brew_Undefined");
      potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
    }

    potionMeta.setDisplayName(P.p.color("&f" + cookedName));
    // This effect stores the UID in its Duration
    potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
    potion.setItemMeta(potionMeta);

    return potion;
  }
Exemplo n.º 2
0
 @Override
 protected ItemStack[] get(Event e) {
   PotionEffectType p = effect.getSingle(e);
   if (p == null) return null;
   ItemStack potion = new Potion(PotionType.getByEffect(p)).toItemStack(1);
   PotionMeta meta = ((PotionMeta) potion.getItemMeta());
   meta.addCustomEffect(new PotionEffect(p, 0, 0), true);
   potion.setItemMeta(meta);
   return Collect.asArray(potion);
 }
Exemplo n.º 3
0
  public static ItemStack createItemStack() {
    ItemStack ret = new ItemStack(Material.POTION, 1, POTION_VALUES.get(0).shortValue());

    PotionMeta meta = (PotionMeta) ret.getItemMeta();
    meta.setDisplayName(NAME);
    meta.setLore(LORE);
    meta.addCustomEffect(EFFECT, false);
    ret.setItemMeta(meta);

    return ret;
  }
Exemplo n.º 4
0
  public static void transferPotionMeta(PotionMeta meta, JsonObject json, boolean meta2json) {
    if (meta2json) {
      if (!meta.hasCustomEffects()) return;
      json.add(POTION_EFFECTS, convertPotionEffectList(meta.getCustomEffects()));
    } else {
      JsonElement element = json.get(POTION_EFFECTS);
      if (element == null) element = json.get(POTION_EFFECTS_OLD);
      if (element == null) return;

      meta.clearCustomEffects();
      for (PotionEffect pe : convertPotionEffectList(element)) {
        meta.addCustomEffect(pe, false);
      }
    }
  }
Exemplo n.º 5
0
  // Create a Potion from this Recipe with best values. Quality can be set, but will reset to 10 if
  // put in a barrel
  public ItemStack create(int quality) {
    ItemStack potion = new ItemStack(Material.POTION);
    PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();

    int uid = Brew.generateUID();

    ArrayList<ItemStack> list = new ArrayList<ItemStack>(ingredients.size());
    for (ItemStack item : ingredients) {
      if (item.getDurability() == -1) {
        list.add(new ItemStack(item.getType(), item.getAmount()));
      } else {
        list.add(item.clone());
      }
    }

    BIngredients bIngredients = new BIngredients(list, cookingTime);

    Brew brew =
        new Brew(
            uid,
            bIngredients,
            quality,
            distillruns,
            getAge(),
            wood,
            getName(5),
            false,
            false,
            true);

    potion.setDurability(Brew.PotionColor.valueOf(getColor()).getColorId(false));
    potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
    // This effect stores the UID in its Duration
    potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);

    brew.convertLore(potionMeta, false);
    Brew.addOrReplaceEffects(potionMeta, effects, quality);

    potion.setItemMeta(potionMeta);
    return potion;
  }
Exemplo n.º 6
0
 public static ItemStack loadPotion(ItemStack potion, String name) {
   if (potion.getType() != Material.POTION) return potion;
   PotionMeta meta = (PotionMeta) potion.getItemMeta();
   meta.clearCustomEffects();
   ConfigurationSection potionYaml = getSection(name);
   if (potionYaml == null) return potion;
   for (String index : potionYaml.getKeys(false)) {
     ConfigurationSection effectYaml = potionYaml.getConfigurationSection(index);
     PotionEffect effect =
         new PotionEffect(
             ItemController.matchPotionEffect(effectYaml.getString("type")),
             effectYaml.getInt("duration", 600),
             effectYaml.getInt("amplifier", 1) - 1,
             effectYaml.getBoolean("showParticles", true));
     meta.addCustomEffect(effect, true);
   }
   if (!meta.getCustomEffects().isEmpty())
     meta.setMainEffect(meta.getCustomEffects().get(0).getType());
   potion.setItemMeta(meta);
   return potion;
 }
Exemplo n.º 7
0
 private List<MobDrop> getDefaultDrops(EntityType entityType) {
   List<MobDrop> drops = new ArrayList<>();
   switch (entityType) {
     case DROPPED_ITEM:
       break;
     case EXPERIENCE_ORB:
       break;
     case LEASH_HITCH:
       break;
     case PAINTING:
       break;
     case ARROW:
       break;
     case SNOWBALL:
       break;
     case FIREBALL:
       break;
     case SMALL_FIREBALL:
       break;
     case ENDER_PEARL:
       break;
     case ENDER_SIGNAL:
       break;
     case THROWN_EXP_BOTTLE:
       break;
     case ITEM_FRAME:
       break;
     case WITHER_SKULL:
       break;
     case PRIMED_TNT:
       break;
     case FALLING_BLOCK:
       break;
     case FIREWORK:
       break;
     case MINECART_COMMAND:
       break;
     case BOAT:
       break;
     case MINECART:
       break;
     case MINECART_CHEST:
       break;
     case MINECART_FURNACE:
       break;
     case MINECART_TNT:
       break;
     case MINECART_HOPPER:
       break;
     case MINECART_MOB_SPAWNER:
       break;
     case CREEPER:
       for (int i = 0; i < 40; i++) {
         drops.add(
             new MobDrop(
                 i, i, 90, new ItemStack(Material.SULPHUR, (int) Math.ceil((double) i / 2D))));
       }
       break;
     case SKELETON:
       for (int i = 0; i < 40; i++) {
         drops.add(
             new MobDrop(
                 i, i, 50, new ItemStack(Material.ARROW, (int) Math.ceil((double) i / 2D))));
         drops.add(
             new MobDrop(
                 i, i, 50, new ItemStack(Material.BONE, (int) Math.ceil((double) i / 2D))));
       }
       drops.add(new MobDrop(5, -1, 5, new ItemStack(Material.BOW, 1)));
       break;
     case SPIDER:
     case CAVE_SPIDER:
       for (int i = 0; i < 40; i++) {
         drops.add(
             new MobDrop(
                 i, i, 75, new ItemStack(Material.STRING, (int) Math.ceil((double) i / 4D))));
         drops.add(
             new MobDrop(
                 i, i, 20, new ItemStack(Material.SPIDER_EYE, (int) Math.ceil((double) i / 8D))));
         // ItemStack spiderVenom = new Potion(PotionType.POISON).toItemStack(i);
         ItemStack spiderVenom = new ItemStack(Material.POTION, i);
         PotionMeta potionMeta = (PotionMeta) spiderVenom.getItemMeta();
         potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.POISON, 120, 1), false);
         spiderVenom.setItemMeta(potionMeta);
         ItemMeta spiderVenomMeta = spiderVenom.getItemMeta();
         spiderVenomMeta.setDisplayName("Spider venom");
         spiderVenom.setItemMeta(spiderVenomMeta);
         drops.add(new MobDrop(i, i, 2, spiderVenom));
       }
       drops.add(new MobDrop(5, 10, 5, new ItemStack(Material.NETHER_STALK)));
       break;
     case GIANT:
       drops.add(new MobDrop(0, -1, 100, new ItemStack(Material.BONE, 64)));
       drops.add(new MobDrop(0, -1, 100, new ItemStack(Material.ROTTEN_FLESH, 64)));
       break;
     case ZOMBIE:
       drops.add(new MobDrop(0, -1, 90, new ItemStack(Material.ROTTEN_FLESH)));
       drops.add(new MobDrop(0, -1, 30, new ItemStack(Material.ROTTEN_FLESH)));
       break;
     case SLIME:
       for (int i = 0; i < 40; i++) {
         drops.add(new MobDrop(i, i, 100, new ItemStack(Material.SLIME_BALL, i)));
       }
       break;
     case GHAST:
       for (int i = 0; i < 40; i++) {
         drops.add(new MobDrop(i, i, 50, new ItemStack(Material.GHAST_TEAR, i)));
         drops.add(new MobDrop(i, i, 50, new ItemStack(Material.SULPHUR, i)));
       }
       break;
     case PIG_ZOMBIE:
       drops.add(new MobDrop(0, 5, 90, new ItemStack(Material.GOLD_NUGGET)));
       drops.add(new MobDrop(5, 10, 80, new ItemStack(Material.GOLD_INGOT)));
       for (int i = 10; i < 40; i += 10) {
         drops.add(new MobDrop(i, i + 10, i * 2, new ItemStack(Material.GOLD_SWORD)));
       }
       break;
     case ENDERMAN:
       drops.add(new MobDrop(0, -1, 100, new ItemStack(Material.ENDER_PEARL)));
       drops.add(new MobDrop(0, -1, 50, new ItemStack(Material.ENDER_PEARL)));
       drops.add(new MobDrop(20, -1, 20, new ItemStack(Material.EYE_OF_ENDER)));
       break;
     case SILVERFISH:
       ItemStack silverfishDroppings1 = new ItemStack(Material.PUMPKIN_SEEDS);
       ItemMeta meta1 = silverfishDroppings1.getItemMeta();
       meta1.setDisplayName("Silverfish droppings");
       silverfishDroppings1.setItemMeta(meta1);
       drops.add(new MobDrop(0, -1, 20, silverfishDroppings1));
       ItemStack silverfishDroppings2 = new ItemStack(Material.MELON_SEEDS);
       ItemMeta meta2 = silverfishDroppings2.getItemMeta();
       meta2.setDisplayName("Silverfish droppings");
       silverfishDroppings2.setItemMeta(meta2);
       drops.add(new MobDrop(0, -1, 20, silverfishDroppings2));
       ItemStack silverfishDroppings3 = new ItemStack(Material.SEEDS);
       ItemMeta meta3 = silverfishDroppings3.getItemMeta();
       meta3.setDisplayName("Silverfish droppings");
       silverfishDroppings3.setItemMeta(meta3);
       drops.add(new MobDrop(0, -1, 20, silverfishDroppings3));
       break;
     case BLAZE:
       for (int i = 0; i < 40; i++) {
         drops.add(new MobDrop(i, i, 75, new ItemStack(Material.BLAZE_ROD)));
       }
       drops.add(new MobDrop(0, -1, 90, new ItemStack(Material.BLAZE_POWDER, 3)));
       break;
     case MAGMA_CUBE:
       drops.add(new MobDrop(0, -1, 90, new ItemStack(Material.MAGMA_CREAM, 5)));
       break;
     case ENDER_DRAGON:
       drops.add(new MobDrop(0, -1, 100, new ItemStack(Material.DRAGON_EGG)));
       break;
     case WITHER:
       // ItemStack witherVenom = new Potion(PotionType.INSTANT_DAMAGE, 2).toItemStack(5);
       ItemStack witherVenom = new ItemStack(Material.POTION);
       ItemMeta witherVenomMeta = witherVenom.getItemMeta();
       witherVenomMeta.setDisplayName("Wither venom");
       PotionMeta witherVenomPotionMeta = (PotionMeta) witherVenomMeta;
       witherVenomPotionMeta.addCustomEffect(
           new PotionEffect(PotionEffectType.HARM, 120, 2), false);
       witherVenom.setItemMeta(witherVenomMeta);
       drops.add(new MobDrop(0, -1, 2, witherVenom));
       break;
     case BAT:
       ItemStack batFang = new ItemStack(Material.GHAST_TEAR);
       ItemMeta batFangMeta = batFang.getItemMeta();
       batFangMeta.setDisplayName("Bat fang");
       batFang.setItemMeta(batFangMeta);
       drops.add(new MobDrop(0, -1, 80, batFang));
       break;
     case WITCH:
       for (PotionEffectType potionEffectType : PotionEffectType.values()) {
         ItemStack potion = new ItemStack(Material.POTION);
         PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
         potionMeta.addCustomEffect(new PotionEffect(potionEffectType, 120, 1), false);
         potion.setItemMeta(potionMeta);
         drops.add(new MobDrop(0, -1, 5, potion));
       }
       break;
     case PIG:
       drops.add(new MobDrop(0, -1, 90, new ItemStack(Material.PORK)));
       drops.add(new MobDrop(0, -1, 10, new ItemStack(Material.GRILLED_PORK)));
       break;
     case SHEEP:
       ItemStack lampChop = new ItemStack(Material.PORK, 1);
       ItemMeta lambChop = lampChop.getItemMeta();
       lambChop.setDisplayName("Lamb chop");
       lampChop.setItemMeta(lambChop);
       drops.add(new MobDrop(0, -1, 60, lampChop));
       drops.add(new MobDrop(0, -1, 100, new ItemStack(Material.WOOL, 5)));
       break;
     case COW:
       drops.add(new MobDrop(0, -1, 90, new ItemStack(Material.RAW_BEEF)));
       drops.add(new MobDrop(0, -1, 10, new ItemStack(Material.COOKED_BEEF)));
       break;
     case CHICKEN:
       drops.add(new MobDrop(0, -1, 90, new ItemStack(Material.RAW_CHICKEN)));
       drops.add(new MobDrop(0, -1, 10, new ItemStack(Material.COOKED_CHICKEN)));
       break;
     case SQUID:
       drops.add(new MobDrop(0, -1, 100, new ItemStack(Material.INK_SACK)));
       break;
     case WOLF:
       drops.add(new MobDrop(0, -1, 100, new ItemStack(Material.BONE)));
       break;
     case MUSHROOM_COW:
       drops.add(new MobDrop(0, -1, 50, new ItemStack(Material.BROWN_MUSHROOM, 5)));
       drops.add(new MobDrop(0, -1, 50, new ItemStack(Material.RED_MUSHROOM, 5)));
       break;
     case SNOWMAN:
       drops.add(new MobDrop(0, -1, 60, new ItemStack(Material.SNOW_BALL, 16)));
       drops.add(new MobDrop(0, -1, 30, new ItemStack(Material.SNOW_BLOCK)));
       drops.add(new MobDrop(0, -1, 20, new ItemStack(Material.PUMPKIN)));
       break;
     case OCELOT:
       drops.add(new MobDrop(0, -1, 90, new ItemStack(Material.RAW_FISH)));
       break;
     case IRON_GOLEM:
       drops.add(new MobDrop(0, -1, 100, new ItemStack(Material.IRON_INGOT, 8)));
       break;
     case HORSE:
       drops.add(new MobDrop(0, -1, 30, new ItemStack(Material.HAY_BLOCK)));
       break;
     case VILLAGER:
       drops.add(new MobDrop(0, -1, 20, new ItemStack(Material.EMERALD)));
       break;
     case ENDER_CRYSTAL:
       drops.add(new MobDrop(0, -1, 100, new ItemStack(Material.ENDER_PEARL, 32)));
       break;
     case SPLASH_POTION:
       break;
     case EGG:
       break;
     case FISHING_HOOK:
       break;
     case LIGHTNING:
       break;
     case WEATHER:
       break;
     case PLAYER:
       break;
     case COMPLEX_PART:
       break;
     case UNKNOWN:
       break;
   }
   return drops;
 }
Exemplo n.º 8
0
  @SuppressWarnings("deprecation")
  public static ItemStack parseItemStack(String s) {
    try {
      String[] gSplit = s.split(" ");
      ItemStack is = null;

      // ITEM ID / MATERIAL / SUBID
      String[] idsSplit = gSplit[0].split(":");
      try {
        is = new ItemStack(Integer.parseInt(idsSplit[0]));
      } catch (NumberFormatException e) {
        is = new ItemStack(Material.valueOf(idsSplit[0]));
      }

      if (idsSplit.length > 1) is.setDurability(Short.parseShort(idsSplit[1]));

      if (gSplit.length > 1) {
        int metaStart = 2;

        try {
          is.setAmount(Integer.parseInt(gSplit[1]));
        } catch (NumberFormatException e) {
          metaStart = 1;
        }
        ItemMeta im = is.getItemMeta();
        for (int meta = metaStart; meta < gSplit.length; meta++) {
          String rawKey = gSplit[meta];
          String[] split = rawKey.split(":");
          String key = split[0];

          if (key.equalsIgnoreCase("name")) {
            im.setDisplayName(
                ChatColor.translateAlternateColorCodes('&', split[1]).replace("_", " "));
          } else if (key.equalsIgnoreCase("lore")) {
            List<String> lore = new ArrayList<>();
            for (String line : split[1].split("//")) {
              lore.add(ChatColor.translateAlternateColorCodes('&', line).replace("_", " "));
            }
            im.setLore(lore);
          } else if (key.equalsIgnoreCase("color") && im instanceof LeatherArmorMeta) {
            LeatherArmorMeta lam = (LeatherArmorMeta) im;
            String[] csplit = split[1].split(",");
            Color color =
                Color.fromBGR(
                    Integer.parseInt(csplit[0]),
                    Integer.parseInt(csplit[1]),
                    Integer.parseInt(csplit[2]));
            lam.setColor(color);
          } else if (key.equalsIgnoreCase("effect") && im instanceof PotionMeta) {
            PotionMeta pm = (PotionMeta) im;
            String[] psplit = split[1].split(",");
            pm.addCustomEffect(
                new PotionEffect(
                    PotionEffectType.getByName(psplit[0]),
                    Integer.parseInt(psplit[1]) * 20,
                    Integer.parseInt(psplit[2])),
                true);
          } else if (key.equalsIgnoreCase("player") && im instanceof SkullMeta) {
            ((SkullMeta) im).setOwner(split[1]);
          } else if (key.equalsIgnoreCase("enchant")) {
            String[] esplit = split[1].split(",");
            im.addEnchant(getEnchantment(esplit[0]), Integer.parseInt(esplit[1]), true);
          }
        }
        is.setItemMeta(im);
      }

      return is;
    } catch (Exception e) {
      System.err.println(
          "[SurvivalGames] Cannot parse ItemStack: "
              + s
              + " - Mabye this is the reason: "
              + e.toString());
      return null;
    }
  }