diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java index 1182046a5..efa2bf12d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java @@ -43,9 +43,7 @@ public class Multimeter extends SimpleSlimefunItem { if (e.getClickedBlock().isPresent() && block.isPresent()) { SlimefunItem item = block.get(); - if (item instanceof EnergyNetComponent) { - EnergyNetComponent component = (EnergyNetComponent) item; - + if (item instanceof EnergyNetComponent component) { if (component.isChargeable()) { e.cancel(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/SolarHelmet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/SolarHelmet.java index 628d0c73f..1a87d59aa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/SolarHelmet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/SolarHelmet.java @@ -67,8 +67,8 @@ public class SolarHelmet extends SlimefunItem { private void recharge(@Nullable ItemStack item) { SlimefunItem sfItem = SlimefunItem.getByItem(item); - if (sfItem instanceof Rechargeable) { - ((Rechargeable) sfItem).addItemCharge(item, charge.getValue().floatValue()); + if (sfItem instanceof Rechargeable rechargeable) { + rechargeable.addItemCharge(item, charge.getValue().floatValue()); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ChargingBench.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ChargingBench.java index b8d2ba0b1..e3395e9f6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ChargingBench.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ChargingBench.java @@ -53,10 +53,10 @@ public class ChargingBench extends AContainer { private boolean charge(Block b, BlockMenu inv, int slot, ItemStack item) { SlimefunItem sfItem = SlimefunItem.getByItem(item); - if (sfItem instanceof Rechargeable) { + if (sfItem instanceof Rechargeable rechargeable) { float charge = getEnergyConsumption() / 2F; - if (((Rechargeable) sfItem).addItemCharge(item, charge)) { + if (rechargeable.addItemCharge(item, charge)) { removeCharge(b.getLocation(), getEnergyConsumption()); } else if (inv.fits(item, getOutputSlots())) { inv.pushItem(item, getOutputSlots()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java index 50b6acf39..c77e660df 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java @@ -37,8 +37,8 @@ public class ElectricFurnace extends AContainer implements NotHopperable { for (FurnaceRecipe recipe : snapshot.getRecipes(FurnaceRecipe.class)) { RecipeChoice choice = recipe.getInputChoice(); - if (choice instanceof MaterialChoice) { - for (Material input : ((MaterialChoice) choice).getChoices()) { + if (choice instanceof MaterialChoice materialChoice) { + for (Material input : materialChoice.getChoices()) { registerRecipe(4, new ItemStack[] { new ItemStack(input) }, new ItemStack[] { recipe.getResult() }); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java index 7879c0bff..b0bfacd9d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java @@ -227,16 +227,14 @@ public class FluidPump extends SimpleSlimefunItem implements Invent } private @Nonnull ItemStack getFilledBucket(@Nonnull Block fluid) { - switch (fluid.getType()) { - case LAVA: - return new ItemStack(Material.LAVA_BUCKET); - case WATER: - case BUBBLE_COLUMN: - return new ItemStack(Material.WATER_BUCKET); - default: + return switch (fluid.getType()) { + case LAVA -> new ItemStack(Material.LAVA_BUCKET); + case WATER, + BUBBLE_COLUMN -> new ItemStack(Material.WATER_BUCKET); + default -> // Fallback for any new liquids - return new ItemStack(Material.BUCKET); - } + new ItemStack(Material.BUCKET); + }; } /** @@ -251,9 +249,8 @@ public class FluidPump extends SimpleSlimefunItem implements Invent if (block.isLiquid()) { BlockData data = block.getBlockData(); - if (data instanceof Levelled) { + if (data instanceof Levelled levelled) { // Check if this is a full block. - Levelled levelled = (Levelled) data; return levelled.getLevel() == 0; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java index edf99ad78..68a570f8a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java @@ -62,7 +62,7 @@ public class AnimalGrowthAccelerator extends AbstractGrowthAccelerator { } private boolean isReadyToGrow(Entity n) { - return n instanceof Ageable && n.isValid() && !((Ageable) n).isAdult(); + return n instanceof Ageable ageable && n.isValid() && !ageable.isAdult(); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AutoBreeder.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AutoBreeder.java index a1daea76e..e62fd7951 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AutoBreeder.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AutoBreeder.java @@ -128,9 +128,7 @@ public class AutoBreeder extends SlimefunItem implements InventoryBlock, EnergyN } private boolean canBreed(@Nonnull Entity n) { - if (n.isValid() && n instanceof Animals) { - Animals animal = (Animals) n; - + if (n.isValid() && n instanceof Animals animal) { return animal.isAdult() && animal.canBreed() && !animal.isLoveMode(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java index 86be0db29..24ecf5d86 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java @@ -75,8 +75,8 @@ public class ProduceCollector extends AContainer implements RecipeDisplayItem { // Mushroom Stew from Mooshrooms addProduce(new AnimalProduce(new ItemStack(Material.BOWL), new ItemStack(Material.MUSHROOM_STEW), n -> { - if (n instanceof MushroomCow) { - return ((MushroomCow) n).isAdult(); + if (n instanceof MushroomCow mushroomCow) { + return mushroomCow.isAdult(); } else { return false; } @@ -158,8 +158,8 @@ public class ProduceCollector extends AContainer implements RecipeDisplayItem { @ParametersAreNonnullByDefault private boolean isValidAnimal(Entity n, Predicate predicate) { - if (n instanceof LivingEntity) { - return predicate.test((LivingEntity) n); + if (n instanceof LivingEntity livingEntity) { + return predicate.test(livingEntity); } else { return false; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/NetherStarReactor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/NetherStarReactor.java index 08c274a8f..47f671ac8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/NetherStarReactor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/NetherStarReactor.java @@ -44,8 +44,8 @@ public abstract class NetherStarReactor extends Reactor { public void extraTick(@Nonnull Location l) { Slimefun.runSync(() -> { for (Entity entity : l.getWorld().getNearbyEntities(l, 5, 5, 5, n -> n instanceof LivingEntity && n.isValid())) { - if (entity instanceof LivingEntity) { - ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 60, 1)); + if (entity instanceof LivingEntity livingEntity) { + livingEntity.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 60, 1)); } } });