mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Small performance improvements
This commit is contained in:
parent
bbd41ff70c
commit
96f657f6e7
@ -38,10 +38,11 @@
|
|||||||
* Block Placers can now place down cake
|
* Block Placers can now place down cake
|
||||||
|
|
||||||
#### Changes
|
#### Changes
|
||||||
|
* Changed item order in guide for the Villager Rune and Nether Goo (All runes are now grouped together)
|
||||||
|
* Ancient Pedestals can now be found under "Magical Gadgets"
|
||||||
* Removed all functionality from the old Automated Crafting Chamber
|
* Removed all functionality from the old Automated Crafting Chamber
|
||||||
* Changed Cargo Motor texture
|
* Changed Cargo Motor texture
|
||||||
* Ancient Pedestals can now be found under "Magical Gadgets"
|
* Small performance improvements
|
||||||
* Changed item order in guide for the Villager Rune and Nether Goo (All runes are now grouped together)
|
|
||||||
|
|
||||||
#### Fixes
|
#### Fixes
|
||||||
* Fixed #1161
|
* Fixed #1161
|
||||||
|
@ -21,6 +21,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||||
@ -238,7 +239,7 @@ public class BlockListener implements Listener {
|
|||||||
|
|
||||||
if (!dummyEvent.isCancelled() && dummyEvent.isDropItems()) {
|
if (!dummyEvent.isCancelled() && dummyEvent.isDropItems()) {
|
||||||
for (ItemStack drop : drops) {
|
for (ItemStack drop : drops) {
|
||||||
if (drop != null && drop.getType() != Material.AIR) {
|
if (drop != null && !drop.getType().isAir()) {
|
||||||
blockAbove.getWorld().dropItemNaturally(blockAbove.getLocation(), drop);
|
blockAbove.getWorld().dropItemNaturally(blockAbove.getLocation(), drop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,10 +252,17 @@ public class BlockListener implements Listener {
|
|||||||
private int getBonusDropsWithFortune(@Nullable ItemStack item, @Nonnull Block b) {
|
private int getBonusDropsWithFortune(@Nullable ItemStack item, @Nonnull Block b) {
|
||||||
int amount = 1;
|
int amount = 1;
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null && !item.getType().isAir() && item.hasItemMeta()) {
|
||||||
int fortuneLevel = item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
|
/*
|
||||||
|
* Small performance optimization:
|
||||||
|
* ItemStack#getEnchantmentLevel() calls ItemStack#getItemMeta(), so if
|
||||||
|
* we are handling more than one Enchantment, we should access the ItemMeta
|
||||||
|
* directly and re use it.
|
||||||
|
*/
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
int fortuneLevel = meta.getEnchantLevel(Enchantment.LOOT_BONUS_BLOCKS);
|
||||||
|
|
||||||
if (fortuneLevel > 0 && !item.containsEnchantment(Enchantment.SILK_TOUCH)) {
|
if (fortuneLevel > 0 && !meta.hasEnchant(Enchantment.SILK_TOUCH)) {
|
||||||
Random random = ThreadLocalRandom.current();
|
Random random = ThreadLocalRandom.current();
|
||||||
|
|
||||||
amount = Math.max(1, random.nextInt(fortuneLevel + 2) - 1);
|
amount = Math.max(1, random.nextInt(fortuneLevel + 2) - 1);
|
||||||
|
@ -278,7 +278,14 @@ public class TalismanListener implements Listener {
|
|||||||
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
|
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
|
||||||
|
|
||||||
// We are going to ignore Silk Touch here
|
// We are going to ignore Silk Touch here
|
||||||
if (item.getType() != Material.AIR && item.getAmount() > 0 && !item.containsEnchantment(Enchantment.SILK_TOUCH)) {
|
if (item.getType() != Material.AIR && item.getAmount() > 0) {
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
|
// Ignore Silk Touch Enchantment
|
||||||
|
if (meta.hasEnchant(Enchantment.SILK_TOUCH)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Material type = e.getBlockState().getType();
|
Material type = e.getBlockState().getType();
|
||||||
|
|
||||||
// We only want to double ores
|
// We only want to double ores
|
||||||
@ -286,7 +293,7 @@ public class TalismanListener implements Listener {
|
|||||||
Collection<Item> drops = e.getItems();
|
Collection<Item> drops = e.getItems();
|
||||||
|
|
||||||
if (Talisman.trigger(e, SlimefunItems.TALISMAN_MINER, false)) {
|
if (Talisman.trigger(e, SlimefunItems.TALISMAN_MINER, false)) {
|
||||||
int dropAmount = getAmountWithFortune(type, item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS));
|
int dropAmount = getAmountWithFortune(type, meta.getEnchantLevel(Enchantment.LOOT_BONUS_BLOCKS));
|
||||||
|
|
||||||
// Keep track of whether we actually doubled the drops or not
|
// Keep track of whether we actually doubled the drops or not
|
||||||
boolean doubledDrops = false;
|
boolean doubledDrops = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user