Created
May 17, 2021 22:08
-
-
Save WizardlyBump17/c60c13ec9ebbaa7be2a7294904b63443 to your computer and use it in GitHub Desktop.
gambiarra pra tentar pegar os drops de um item, funciona com fortuna e silk touch kappa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final Map<Material, Material> DROPS = new HashMap<Material, Material>() {{ | |
put(Material.CARROT, Material.CARROT_ITEM); | |
put(Material.POTATO, Material.POTATO_ITEM); | |
put(Material.NETHER_WARTS, Material.NETHER_STALK); | |
put(Material.COCOA, Material.INK_SACK); | |
put(Material.COAL_ORE, Material.COAL); | |
put(Material.DIAMOND_ORE, Material.DIAMOND); | |
put(Material.EMERALD_ORE, Material.EMERALD); | |
put(Material.LAPIS_ORE, Material.INK_SACK); | |
put(Material.REDSTONE_ORE, Material.REDSTONE); | |
put(Material.GLOWING_REDSTONE_ORE, Material.REDSTONE); | |
put(Material.QUARTZ_ORE, Material.QUARTZ); | |
}}; | |
public static List<ItemStack> getDrops(Block block, ItemStack itemStack, Random random) { | |
Material type = block.getType(); | |
List<BlockDrop> blockDrops = getDrop(type, itemStack.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS), random, itemStack.containsEnchantment(Enchantment.SILK_TOUCH)); | |
return blockDrops.stream().map((drop) -> new ItemStack(drop.drop.getItemType(), drop.count, drop.drop.getData())).collect(Collectors.toList()); | |
} | |
private static List<BlockDrop> getDrop(Material material, int fortune, Random random, boolean silkTouch) { | |
switch (material) { | |
case STONE: | |
return Collections.singletonList(new BlockDrop(new MaterialData(silkTouch ? Material.COBBLESTONE : material), 1)); | |
case LAPIS_ORE: | |
return silkTouch ? Collections.singletonList(new BlockDrop(new MaterialData(material), 1)) : Collections.singletonList(new BlockDrop(new MaterialData(Material.INK_SACK, (byte) 4), 4 + random.nextInt(5) * dropCount(fortune, random))); | |
case COCOA: | |
return Collections.singletonList(new BlockDrop(new MaterialData(Material.INK_SACK, (byte) 3), 2 + random.nextInt(2))); | |
case CROPS: | |
List<BlockDrop> drops = new ArrayList<>(2); | |
drops.add(new BlockDrop(new MaterialData(Material.WHEAT), 1)); | |
drops.add(new BlockDrop(new MaterialData(Material.SEEDS), random.nextInt(Math.max(silkTouch ? 0 : fortune + 1, 4)))); | |
return drops; | |
case NETHER_WARTS: | |
return Collections.singletonList(new BlockDrop(new MaterialData(Material.NETHER_STALK), 4 + random.nextInt(3) * (silkTouch ? 1 : dropCount(fortune, random)))); | |
default: | |
if (!silkTouch) | |
return Collections.singletonList(new BlockDrop(new MaterialData(DROPS.get(material) == null ? fixMaterial(material) : DROPS.get(material)), DROPS.containsKey(material) ? dropCount(fortune, random) : 1)); | |
return Collections.singletonList(new BlockDrop(new MaterialData(material == Material.GLOWING_REDSTONE_ORE ? Material.REDSTONE_ORE : fixMaterial(material)), 1)); | |
} | |
} | |
private static int dropCount(int fortune, Random random) { | |
return fortune == 0 ? 1 : Math.max(random.nextInt(fortune + 2) - 1, 1); | |
} | |
private static Material fixMaterial(Material material) { | |
switch (material) { | |
case CARROT: return Material.CARROT_ITEM; | |
case POTATO: return Material.POTATO; | |
case COCOA: return Material.INK_SACK; | |
case SUGAR_CANE_BLOCK: return Material.SUGAR_CANE; | |
default: return material; | |
} | |
} | |
@Data | |
static class BlockDrop { | |
final MaterialData drop; | |
final int count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment