1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Small performance improvements for miner talismans

This commit is contained in:
TheBusyBiscuit 2020-08-04 10:19:24 +02:00
parent 7b1e90c7b2
commit 0ff5fc7251
3 changed files with 21 additions and 18 deletions

View File

@ -32,6 +32,7 @@
#### Changes
* Performance improvement for Programmable Android rotations
* Removed Gravel -> Flint recipe from the Grind stone
* Performance improvements for miner talismans
#### Fixes
* Fixed Programmable Androids rotating in the wrong direction

View File

@ -131,8 +131,7 @@ public class Talisman extends SlimefunItem {
}
public static boolean checkFor(Event e, SlimefunItemStack stack) {
SlimefunItem item = SlimefunItem.getByItem(stack);
return checkFor(e, item);
return checkFor(e, stack.getItem());
}
public static boolean checkFor(Event e, SlimefunItem item) {

View File

@ -229,26 +229,29 @@ public class TalismanListener implements Listener {
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
// We only want to double ores
if (MaterialCollections.getAllOres().contains(e.getBlock().getType())) {
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
if (item.getType() != Material.AIR && item.getAmount() > 0) {
List<ItemStack> drops = new ArrayList<>(e.getBlock().getDrops(item));
int dropAmount = 1;
if (item.getType() != Material.AIR && item.getAmount() > 0) {
Collection<ItemStack> drops = e.getBlock().getDrops(item);
int dropAmount = 1;
if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
Random random = ThreadLocalRandom.current();
dropAmount = random.nextInt(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
dropAmount = Math.max(dropAmount, 1);
dropAmount = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (dropAmount + 1);
}
if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
Random random = ThreadLocalRandom.current();
dropAmount = random.nextInt(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
dropAmount = Math.max(dropAmount, 1);
dropAmount = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (dropAmount + 1);
}
if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && MaterialCollections.getAllOres().contains(e.getBlock().getType()) && Talisman.checkFor(e, SlimefunItems.TALISMAN_MINER)) {
for (ItemStack drop : drops) {
if (!drop.getType().isBlock()) {
int amount = Math.max(1, (dropAmount * 2) - drop.getAmount());
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new CustomItem(drop, amount));
if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && Talisman.checkFor(e, SlimefunItems.TALISMAN_MINER)) {
for (ItemStack drop : drops) {
if (!drop.getType().isBlock()) {
int amount = Math.max(1, (dropAmount * 2) - drop.getAmount());
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new CustomItem(drop, amount));
}
}
}
}