public ItemStack getOutcome(boolean isFixedDrops) { if (random.nextDouble() * 100.0D < percentage && material != null) { int dropAmount = isFixedDrops ? range.getMaximumInteger() : range.getMinimumInteger() + random.nextInt( Math.abs(range.getMaximumInteger() - range.getMinimumInteger() + 1)); if (dropAmount > 0) { ItemStack itemStack; if (data == null) { itemStack = new ItemStack(material, dropAmount); } else { MaterialData materialData = new MaterialData(material, data); itemStack = materialData.toItemStack(dropAmount); if (durability != null) { itemStack.setDurability(durability); } } itemStack.addEnchantments(ItemEnchantment.getOutcome(enchantments)); if (itemStack.getAmount() > 0) { return itemStack; } } } return null; }
public static Number pickRange(NumberRange range) { Number result = null; RandomData randomData = new RandomDataImpl(); if (range.getMinimumNumber() instanceof Integer && range.getMaximumNumber() instanceof Integer) { result = randomData.nextInt(range.getMinimumInteger(), range.getMaximumInteger()); } if (range.getMinimumNumber() instanceof Long && range.getMaximumNumber() instanceof Long) { result = randomData.nextLong(range.getMinimumLong(), range.getMaximumLong()); } if (range.getMinimumNumber() instanceof Float && range.getMaximumNumber() instanceof Float) { result = randomData.nextUniform(range.getMinimumFloat(), range.getMaximumFloat()); } if (range.getMinimumNumber() instanceof Double && range.getMaximumNumber() instanceof Double) { result = randomData.nextUniform(range.getMinimumDouble(), range.getMaximumDouble()); } return result; }