From dbf55be230233d6203bc3eb997761fdc730e0f91 Mon Sep 17 00:00:00 2001 From: Sefiraat Date: Sat, 2 Jul 2022 21:51:08 +0100 Subject: [PATCH] Java16 Sonar Changes - 6 --- .../implementation/items/food/Juice.java | 4 +- .../items/magical/InfusedHopper.java | 3 +- .../items/magical/MagicalZombiePills.java | 8 ++-- .../items/magical/runes/EnchantmentRune.java | 4 +- .../items/magical/runes/VillagerRune.java | 18 ++++--- .../items/magical/talismans/Talisman.java | 32 ++++++------- .../items/misc/StrangeNetherGoo.java | 12 ++--- .../items/multiblocks/AbstractSmeltery.java | 5 +- .../items/multiblocks/ArmorForge.java | 11 ++--- .../items/multiblocks/Compressor.java | 5 +- .../multiblocks/EnhancedCraftingTable.java | 15 +++--- .../items/multiblocks/GrindStone.java | 11 ++--- .../items/multiblocks/Juicer.java | 11 ++--- .../items/multiblocks/MagicWorkbench.java | 7 ++- .../items/multiblocks/OreCrusher.java | 11 ++--- .../items/multiblocks/PressureChamber.java | 13 +++-- .../items/multiblocks/miner/MiningTask.java | 7 ++- .../multiblocks/miner/OreDictionary14.java | 31 +++++------- .../multiblocks/miner/OreDictionary16.java | 14 +++--- .../multiblocks/miner/OreDictionary17.java | 47 ++++++++----------- 20 files changed, 115 insertions(+), 154 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Juice.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Juice.java index 9823f9329..f0f434292 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Juice.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Juice.java @@ -49,8 +49,8 @@ public class Juice extends SimpleSlimefunItem { ItemMeta meta = item.getItemMeta(); - if (meta instanceof PotionMeta) { - effects = ((PotionMeta) meta).getCustomEffects(); + if (meta instanceof PotionMeta potionMeta) { + effects = potionMeta.getCustomEffects(); } else { effects = new ArrayList<>(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfusedHopper.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfusedHopper.java index 1523c3d19..e30b47a1a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfusedHopper.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfusedHopper.java @@ -107,8 +107,7 @@ public class InfusedHopper extends SimpleSlimefunItem { } private boolean isValidItem(@Nonnull Location l, @Nonnull Entity entity) { - if (entity instanceof Item && entity.isValid()) { - Item item = (Item) entity; + if (entity instanceof Item item && entity.isValid()) { // Check if the item cannot be picked up or has the "no pickup" metadata return item.getPickupDelay() <= 0 && !SlimefunUtils.hasNoPickupFlag(item) && item.getLocation().distanceSquared(l) > 0.25; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java index 619de8c02..7273db80d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java @@ -61,12 +61,12 @@ public class MagicalZombiePills extends SimpleSlimefunItem { } private boolean findCompatibleItem(@Nonnull Entity n) { - if (n instanceof Item) { - Item item = (Item) n; - + if (n instanceof Item item) { return !isItem(item.getItemStack()); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/VillagerRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/VillagerRune.java index a33ef5eb0..3fb5dc9b0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/VillagerRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/VillagerRune.java @@ -43,10 +43,8 @@ public class VillagerRune extends SimpleSlimefunItem { return; } - if (e.getRightClicked() instanceof Villager) { - Villager v = (Villager) e.getRightClicked(); - - if (v.getProfession() == Profession.NONE || v.getProfession() == Profession.NITWIT) { + if (e.getRightClicked() instanceof Villager villager) { + if (villager.getProfession() == Profession.NONE || villager.getProfession() == Profession.NITWIT) { return; } @@ -55,16 +53,16 @@ public class VillagerRune extends SimpleSlimefunItem { } // Reset Villager - v.setVillagerExperience(0); - v.setVillagerLevel(1); - v.setProfession(Profession.NONE); + villager.setVillagerExperience(0); + villager.setVillagerLevel(1); + villager.setProfession(Profession.NONE); e.setCancelled(true); double offset = ThreadLocalRandom.current().nextDouble(0.5); - v.getWorld().playSound(v.getLocation(), Sound.ENTITY_VILLAGER_CELEBRATE, 1, 1.4F); - v.getWorld().spawnParticle(Particle.CRIMSON_SPORE, v.getLocation(), 10, 0, offset / 2, 0, 0); - v.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, v.getLocation(), 5, 0.04, 1, 0.04); + villager.getWorld().playSound(villager.getLocation(), Sound.ENTITY_VILLAGER_CELEBRATE, 1, 1.4F); + villager.getWorld().spawnParticle(Particle.CRIMSON_SPORE, villager.getLocation(), 10, 0, offset / 2, 0, 0); + villager.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, villager.getLocation(), 5, 0.04, 1, 0.04); } }; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 23398b7b8..7ecc6f6fa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -162,12 +162,10 @@ public class Talisman extends SlimefunItem { @ParametersAreNonnullByDefault public static boolean trigger(Event e, SlimefunItem item, boolean sendMessage) { - if (!(item instanceof Talisman)) { + if (!(item instanceof Talisman talisman)) { return false; } - Talisman talisman = (Talisman) item; - if (ThreadLocalRandom.current().nextInt(100) > talisman.getChance()) { return false; } @@ -239,8 +237,8 @@ public class Talisman extends SlimefunItem { @ParametersAreNonnullByDefault private static void cancelEvent(Event e, Talisman talisman) { - if (e instanceof Cancellable && talisman.isEventCancelled()) { - ((Cancellable) e).setCancelled(true); + if (e instanceof Cancellable cancellable && talisman.isEventCancelled()) { + cancellable.setCancelled(true); } } @@ -301,18 +299,18 @@ public class Talisman extends SlimefunItem { @Nullable private static Player getPlayerByEventType(@Nonnull Event e) { - if (e instanceof EntityDeathEvent) { - return ((EntityDeathEvent) e).getEntity().getKiller(); - } else if (e instanceof BlockBreakEvent) { - return ((BlockBreakEvent) e).getPlayer(); - } else if (e instanceof BlockDropItemEvent) { - return ((BlockDropItemEvent) e).getPlayer(); - } else if (e instanceof PlayerEvent) { - return ((PlayerEvent) e).getPlayer(); - } else if (e instanceof EntityEvent) { - return (Player) ((EntityEvent) e).getEntity(); - } else if (e instanceof EnchantItemEvent) { - return ((EnchantItemEvent) e).getEnchanter(); + if (e instanceof EntityDeathEvent entityDeathEvent) { + return entityDeathEvent.getEntity().getKiller(); + } else if (e instanceof BlockBreakEvent blockBreakEvent) { + return blockBreakEvent.getPlayer(); + } else if (e instanceof BlockDropItemEvent blockDropItemEvent) { + return blockDropItemEvent.getPlayer(); + } else if (e instanceof PlayerEvent playerEvent) { + return playerEvent.getPlayer(); + } else if (e instanceof EntityEvent entityEvent) { + return (Player) entityEvent.getEntity(); + } else if (e instanceof EnchantItemEvent enchantItemEvent) { + return enchantItemEvent.getEnchanter(); } return null; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/StrangeNetherGoo.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/StrangeNetherGoo.java index b4f1591e9..754a5f88b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/StrangeNetherGoo.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/StrangeNetherGoo.java @@ -70,10 +70,8 @@ public class StrangeNetherGoo extends SimpleSlimefunItem impleme private EntityInteractHandler onRightClickEntity() { return (e, item, hand) -> { - if (e.getRightClicked() instanceof Sheep) { - Sheep s = (Sheep) e.getRightClicked(); - - if (s.getCustomName() != null) { + if (e.getRightClicked() instanceof Sheep sheep) { + if (sheep.getCustomName() != null) { e.setCancelled(true); return; } @@ -83,9 +81,9 @@ public class StrangeNetherGoo extends SimpleSlimefunItem impleme } // Give Sheep color, name and effect - s.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 60, 2)); - s.setColor(DyeColor.PURPLE); - s.setCustomName(ChatColor.DARK_PURPLE + "Tainted Sheep"); + sheep.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 60, 2)); + sheep.setColor(DyeColor.PURPLE); + sheep.setCustomName(ChatColor.DARK_PURPLE + "Tainted Sheep"); e.setCancelled(true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractSmeltery.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractSmeltery.java index 51f702558..dd4ee9a26 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractSmeltery.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractSmeltery.java @@ -41,9 +41,8 @@ abstract class AbstractSmeltery extends MultiBlockMachine { Block dispBlock = b.getRelative(BlockFace.DOWN); BlockState state = PaperLib.getBlockState(dispBlock, false).getState(); - if (state instanceof Dispenser) { - Dispenser disp = (Dispenser) state; - Inventory inv = disp.getInventory(); + if (state instanceof Dispenser dispenser) { + Inventory inv = dispenser.getInventory(); List inputs = RecipeType.getRecipeInputList(this); for (int i = 0; i < inputs.size(); i++) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/ArmorForge.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/ArmorForge.java index e1e78401a..fecd80cba 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/ArmorForge.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/ArmorForge.java @@ -31,12 +31,11 @@ public class ArmorForge extends AbstractCraftingTable { @Override public void onInteract(Player p, Block b) { - Block dispenser = b.getRelative(BlockFace.DOWN); - BlockState state = PaperLib.getBlockState(dispenser, false).getState(); + Block possibleDispenser = b.getRelative(BlockFace.DOWN); + BlockState state = PaperLib.getBlockState(possibleDispenser, false).getState(); - if (state instanceof Dispenser) { - Dispenser disp = (Dispenser) state; - Inventory inv = disp.getInventory(); + if (state instanceof Dispenser dispenser) { + Inventory inv = dispenser.getInventory(); List inputs = RecipeType.getRecipeInputList(this); for (int i = 0; i < inputs.size(); i++) { @@ -44,7 +43,7 @@ public class ArmorForge extends AbstractCraftingTable { ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone(); if (SlimefunUtils.canPlayerUseItem(p, output, true)) { - craft(p, output, inv, dispenser); + craft(p, output, inv, possibleDispenser); } return; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Compressor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Compressor.java index 3fc131501..16a22cba6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Compressor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Compressor.java @@ -57,9 +57,8 @@ public class Compressor extends MultiBlockMachine { Block dispBlock = b.getRelative(BlockFace.DOWN); BlockState state = PaperLib.getBlockState(dispBlock, false).getState(); - if (state instanceof Dispenser) { - Dispenser disp = (Dispenser) state; - Inventory inv = disp.getInventory(); + if (state instanceof Dispenser dispenser) { + Inventory inv = dispenser.getInventory(); for (ItemStack item : inv.getContents()) { for (ItemStack recipeInput : RecipeType.getRecipeInputs(this)) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java index 7a0bb1a3b..37bbf2fc2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java @@ -33,12 +33,11 @@ public class EnhancedCraftingTable extends AbstractCraftingTable { @Override public void onInteract(Player p, Block b) { - Block dispenser = b.getRelative(BlockFace.DOWN); - BlockState state = PaperLib.getBlockState(dispenser, false).getState(); + Block possibleDispenser = b.getRelative(BlockFace.DOWN); + BlockState state = PaperLib.getBlockState(possibleDispenser, false).getState(); - if (state instanceof Dispenser) { - Dispenser disp = (Dispenser) state; - Inventory inv = disp.getInventory(); + if (state instanceof Dispenser dispenser) { + Inventory inv = dispenser.getInventory(); List inputs = RecipeType.getRecipeInputList(this); for (int i = 0; i < inputs.size(); i++) { @@ -46,7 +45,7 @@ public class EnhancedCraftingTable extends AbstractCraftingTable { ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone(); if (SlimefunUtils.canPlayerUseItem(p, output, true)) { - craft(inv, dispenser, p, b, output); + craft(inv, possibleDispenser, p, b, output); } return; @@ -68,8 +67,8 @@ public class EnhancedCraftingTable extends AbstractCraftingTable { if (outputInv != null) { SlimefunItem sfItem = SlimefunItem.getByItem(output); - if (sfItem instanceof SlimefunBackpack) { - upgradeBackpack(p, inv, (SlimefunBackpack) sfItem, output); + if (sfItem instanceof SlimefunBackpack slimefunBackpack) { + upgradeBackpack(p, inv, slimefunBackpack, output); } for (int j = 0; j < 9; j++) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/GrindStone.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/GrindStone.java index c6ea3ed0f..6ec794695 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/GrindStone.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/GrindStone.java @@ -106,18 +106,17 @@ public class GrindStone extends MultiBlockMachine { @Override public void onInteract(Player p, Block b) { - Block dispBlock = b.getRelative(BlockFace.DOWN); - BlockState state = PaperLib.getBlockState(dispBlock, false).getState(); + Block possibleDispenser = b.getRelative(BlockFace.DOWN); + BlockState state = PaperLib.getBlockState(possibleDispenser, false).getState(); - if (state instanceof Dispenser) { - Dispenser disp = (Dispenser) state; - Inventory inv = disp.getInventory(); + if (state instanceof Dispenser dispenser) { + Inventory inv = dispenser.getInventory(); for (ItemStack current : inv.getContents()) { for (ItemStack convert : RecipeType.getRecipeInputs(this)) { if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) { ItemStack output = RecipeType.getRecipeOutput(this, convert); - Inventory outputInv = findOutputInventory(output, dispBlock, inv); + Inventory outputInv = findOutputInventory(output, possibleDispenser, inv); if (outputInv != null) { ItemStack removing = current.clone(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Juicer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Juicer.java index 9f9ca54f2..2486372ff 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Juicer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Juicer.java @@ -50,18 +50,17 @@ public class Juicer extends MultiBlockMachine { @Override public void onInteract(Player p, Block b) { - Block dispBlock = b.getRelative(BlockFace.DOWN); - BlockState state = PaperLib.getBlockState(dispBlock, false).getState(); + Block possibleDispenser = b.getRelative(BlockFace.DOWN); + BlockState state = PaperLib.getBlockState(possibleDispenser, false).getState(); - if (state instanceof Dispenser) { - Dispenser disp = (Dispenser) state; - Inventory inv = disp.getInventory(); + if (state instanceof Dispenser dispenser) { + Inventory inv = dispenser.getInventory(); for (ItemStack current : inv.getContents()) { for (ItemStack convert : RecipeType.getRecipeInputs(this)) { if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) { ItemStack adding = RecipeType.getRecipeOutput(this, convert); - Inventory outputInv = findOutputInventory(adding, dispBlock, inv); + Inventory outputInv = findOutputInventory(adding, possibleDispenser, inv); if (outputInv != null) { ItemStack removing = current.clone(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MagicWorkbench.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MagicWorkbench.java index 5d8da3c28..6470df750 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MagicWorkbench.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MagicWorkbench.java @@ -43,8 +43,7 @@ public class MagicWorkbench extends AbstractCraftingTable { BlockState state = PaperLib.getBlockState(dispenser, false).getState(); - if (state instanceof Dispenser) { - Dispenser disp = (Dispenser) state; + if (state instanceof Dispenser disp) { Inventory inv = disp.getInventory(); List inputs = RecipeType.getRecipeInputList(this); @@ -76,8 +75,8 @@ public class MagicWorkbench extends AbstractCraftingTable { if (outputInv != null) { SlimefunItem sfItem = SlimefunItem.getByItem(output); - if (sfItem instanceof SlimefunBackpack) { - upgradeBackpack(p, inv, (SlimefunBackpack) sfItem, output); + if (sfItem instanceof SlimefunBackpack slimefunBackpack) { + upgradeBackpack(p, inv, slimefunBackpack, output); } for (int j = 0; j < 9; j++) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java index 14da7829d..84851c0ea 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java @@ -173,18 +173,17 @@ public class OreCrusher extends MultiBlockMachine { @Override public void onInteract(Player p, Block b) { - Block dispBlock = b.getRelative(BlockFace.DOWN); - BlockState state = PaperLib.getBlockState(dispBlock, false).getState(); + Block possibleDispenser = b.getRelative(BlockFace.DOWN); + BlockState state = PaperLib.getBlockState(possibleDispenser, false).getState(); - if (state instanceof Dispenser) { - Dispenser disp = (Dispenser) state; - Inventory inv = disp.getInventory(); + if (state instanceof Dispenser dispenser) { + Inventory inv = dispenser.getInventory(); for (ItemStack current : inv.getContents()) { for (ItemStack convert : RecipeType.getRecipeInputs(this)) { if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) { ItemStack adding = RecipeType.getRecipeOutput(this, convert); - Inventory outputInv = findOutputInventory(adding, dispBlock, inv); + Inventory outputInv = findOutputInventory(adding, possibleDispenser, inv); if (SlimefunUtils.canPlayerUseItem(p, adding, true)) { if (outputInv != null) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/PressureChamber.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/PressureChamber.java index a5489ce57..70bbaec1e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/PressureChamber.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/PressureChamber.java @@ -39,25 +39,24 @@ public class PressureChamber extends MultiBlockMachine { @Override public void onInteract(Player p, Block b) { - Block dispBlock = b.getRelative(BlockFace.UP).getRelative(BlockFace.UP); - BlockState state = PaperLib.getBlockState(dispBlock, false).getState(); + Block possibleDispenser = b.getRelative(BlockFace.UP).getRelative(BlockFace.UP); + BlockState state = PaperLib.getBlockState(possibleDispenser, false).getState(); - if (state instanceof Dispenser) { - Dispenser disp = (Dispenser) state; - Inventory inv = disp.getInventory(); + if (state instanceof Dispenser dispenser) { + Inventory inv = dispenser.getInventory(); for (ItemStack current : inv.getContents()) { for (ItemStack convert : RecipeType.getRecipeInputs(this)) { if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) { ItemStack output = RecipeType.getRecipeOutput(this, convert); - Inventory outputInv = findOutputInventory(output, dispBlock, inv); + Inventory outputInv = findOutputInventory(output, possibleDispenser, inv); if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(convert.getAmount()); inv.removeItem(removing); - craft(p, b, output, inv, dispBlock); + craft(p, b, output, inv, possibleDispenser); } else { Slimefun.getLocalization().sendMessage(p, "machines.full-inventory", true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/MiningTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/MiningTask.java index da31690ed..9fda2352a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/MiningTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/MiningTask.java @@ -143,7 +143,6 @@ class MiningTask implements Runnable { if (fuelLevel <= 0) { // This Miner has not enough fuel. stop(MinerStoppingReason.NO_FUEL); - return; } }); @@ -268,8 +267,8 @@ class MiningTask implements Runnable { if (chest.getType() == Material.CHEST) { BlockState state = PaperLib.getBlockState(chest, false).getState(); - if (state instanceof Chest) { - Inventory inv = ((Chest) state).getBlockInventory(); + if (state instanceof Chest chest) { + Inventory inv = chest.getBlockInventory(); if (InvUtils.fits(inv, item)) { inv.addItem(item); @@ -299,7 +298,7 @@ class MiningTask implements Runnable { if (chest.getType() == Material.CHEST) { BlockState state = PaperLib.getBlockState(chest, false).getState(); - if (state instanceof Chest) { + if (state instanceof Chest chest) { Inventory inv = ((Chest) state).getBlockInventory(); this.fuelLevel = grabFuelFrom(inv); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary14.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary14.java index 54971fcf8..bf3946253 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary14.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary14.java @@ -19,26 +19,17 @@ class OreDictionary14 implements OreDictionary { @Override @ParametersAreNonnullByDefault public @Nonnull ItemStack getDrops(Material material, Random random) { - switch (material) { - case COAL_ORE: - return new ItemStack(Material.COAL); - case DIAMOND_ORE: - return new ItemStack(Material.DIAMOND); - case EMERALD_ORE: - return new ItemStack(Material.EMERALD); - case REDSTONE_ORE: - return new ItemStack(Material.REDSTONE, 4 + random.nextInt(2)); - case LAPIS_ORE: - return new ItemStack(Material.LAPIS_LAZULI, 4 + random.nextInt(4)); - case NETHER_QUARTZ_ORE: - return new ItemStack(Material.QUARTZ); - case IRON_ORE: - return new ItemStack(Material.IRON_ORE); - case GOLD_ORE: - return new ItemStack(Material.GOLD_ORE); - default: - return new ItemStack(material); - } + return switch (material) { + case COAL_ORE -> new ItemStack(Material.COAL); + case DIAMOND_ORE -> new ItemStack(Material.DIAMOND); + case EMERALD_ORE -> new ItemStack(Material.EMERALD); + case REDSTONE_ORE -> new ItemStack(Material.REDSTONE, 4 + random.nextInt(2)); + case LAPIS_ORE -> new ItemStack(Material.LAPIS_LAZULI, 4 + random.nextInt(4)); + case NETHER_QUARTZ_ORE -> new ItemStack(Material.QUARTZ); + case IRON_ORE -> new ItemStack(Material.IRON_ORE); + case GOLD_ORE -> new ItemStack(Material.GOLD_ORE); + default -> new ItemStack(material); + }; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary16.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary16.java index 242c88ee9..7825caf82 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary16.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary16.java @@ -19,15 +19,13 @@ class OreDictionary16 extends OreDictionary14 { @Override @ParametersAreNonnullByDefault public @Nonnull ItemStack getDrops(Material material, Random random) { - switch (material) { - case NETHER_GOLD_ORE: + return switch (material) { + case NETHER_GOLD_ORE -> // In 1.16, breaking nether gold ores should get gold nuggets - return new ItemStack(Material.GOLD_NUGGET, 2 + random.nextInt(4)); - case ANCIENT_DEBRIS: - return new ItemStack(Material.ANCIENT_DEBRIS); - default: - return super.getDrops(material, random); - } + new ItemStack(Material.GOLD_NUGGET, 2 + random.nextInt(4)); + case ANCIENT_DEBRIS -> new ItemStack(Material.ANCIENT_DEBRIS); + default -> super.getDrops(material, random); + }; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary17.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary17.java index ae1c140eb..7db6e3948 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary17.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary17.java @@ -19,34 +19,25 @@ class OreDictionary17 extends OreDictionary16 { @ParametersAreNonnullByDefault public ItemStack getDrops(Material material, Random random) { // In 1.17, breaking metal ores should get raw metals. Also support deepslate ores. - switch (material) { - case COAL_ORE: - case DEEPSLATE_COAL_ORE: - return new ItemStack(Material.COAL); - case DIAMOND_ORE: - case DEEPSLATE_DIAMOND_ORE: - return new ItemStack(Material.DIAMOND); - case EMERALD_ORE: - case DEEPSLATE_EMERALD_ORE: - return new ItemStack(Material.EMERALD); - case REDSTONE_ORE: - case DEEPSLATE_REDSTONE_ORE: - return new ItemStack(Material.REDSTONE, 4 + random.nextInt(2)); - case LAPIS_ORE: - case DEEPSLATE_LAPIS_ORE: - return new ItemStack(Material.LAPIS_LAZULI, 4 + random.nextInt(4)); - case COPPER_ORE: - case DEEPSLATE_COPPER_ORE: - return new ItemStack(Material.RAW_COPPER); - case IRON_ORE: - case DEEPSLATE_IRON_ORE: - return new ItemStack(Material.RAW_IRON); - case GOLD_ORE: - case DEEPSLATE_GOLD_ORE: - return new ItemStack(Material.RAW_GOLD); - default: - return super.getDrops(material, random); - } + return switch (material) { + case COAL_ORE, + DEEPSLATE_COAL_ORE -> new ItemStack(Material.COAL); + case DIAMOND_ORE, + DEEPSLATE_DIAMOND_ORE -> new ItemStack(Material.DIAMOND); + case EMERALD_ORE, + DEEPSLATE_EMERALD_ORE -> new ItemStack(Material.EMERALD); + case REDSTONE_ORE, + DEEPSLATE_REDSTONE_ORE -> new ItemStack(Material.REDSTONE, 4 + random.nextInt(2)); + case LAPIS_ORE, + DEEPSLATE_LAPIS_ORE -> new ItemStack(Material.LAPIS_LAZULI, 4 + random.nextInt(4)); + case COPPER_ORE, + DEEPSLATE_COPPER_ORE -> new ItemStack(Material.RAW_COPPER); + case IRON_ORE, + DEEPSLATE_IRON_ORE -> new ItemStack(Material.RAW_IRON); + case GOLD_ORE, + DEEPSLATE_GOLD_ORE -> new ItemStack(Material.RAW_GOLD); + default -> super.getDrops(material, random); + }; } }