1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45:51 +00:00

Java16 Sonar Changes - 5

This commit is contained in:
Sefiraat 2022-07-02 21:36:15 +01:00
parent 0f6b6b244c
commit 9f4cb828cb
9 changed files with 23 additions and 30 deletions

View File

@ -43,9 +43,7 @@ public class Multimeter extends SimpleSlimefunItem<ItemUseHandler> {
if (e.getClickedBlock().isPresent() && block.isPresent()) { if (e.getClickedBlock().isPresent() && block.isPresent()) {
SlimefunItem item = block.get(); SlimefunItem item = block.get();
if (item instanceof EnergyNetComponent) { if (item instanceof EnergyNetComponent component) {
EnergyNetComponent component = (EnergyNetComponent) item;
if (component.isChargeable()) { if (component.isChargeable()) {
e.cancel(); e.cancel();

View File

@ -67,8 +67,8 @@ public class SolarHelmet extends SlimefunItem {
private void recharge(@Nullable ItemStack item) { private void recharge(@Nullable ItemStack item) {
SlimefunItem sfItem = SlimefunItem.getByItem(item); SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem instanceof Rechargeable) { if (sfItem instanceof Rechargeable rechargeable) {
((Rechargeable) sfItem).addItemCharge(item, charge.getValue().floatValue()); rechargeable.addItemCharge(item, charge.getValue().floatValue());
} }
} }

View File

@ -53,10 +53,10 @@ public class ChargingBench extends AContainer {
private boolean charge(Block b, BlockMenu inv, int slot, ItemStack item) { private boolean charge(Block b, BlockMenu inv, int slot, ItemStack item) {
SlimefunItem sfItem = SlimefunItem.getByItem(item); SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem instanceof Rechargeable) { if (sfItem instanceof Rechargeable rechargeable) {
float charge = getEnergyConsumption() / 2F; float charge = getEnergyConsumption() / 2F;
if (((Rechargeable) sfItem).addItemCharge(item, charge)) { if (rechargeable.addItemCharge(item, charge)) {
removeCharge(b.getLocation(), getEnergyConsumption()); removeCharge(b.getLocation(), getEnergyConsumption());
} else if (inv.fits(item, getOutputSlots())) { } else if (inv.fits(item, getOutputSlots())) {
inv.pushItem(item, getOutputSlots()); inv.pushItem(item, getOutputSlots());

View File

@ -37,8 +37,8 @@ public class ElectricFurnace extends AContainer implements NotHopperable {
for (FurnaceRecipe recipe : snapshot.getRecipes(FurnaceRecipe.class)) { for (FurnaceRecipe recipe : snapshot.getRecipes(FurnaceRecipe.class)) {
RecipeChoice choice = recipe.getInputChoice(); RecipeChoice choice = recipe.getInputChoice();
if (choice instanceof MaterialChoice) { if (choice instanceof MaterialChoice materialChoice) {
for (Material input : ((MaterialChoice) choice).getChoices()) { for (Material input : materialChoice.getChoices()) {
registerRecipe(4, new ItemStack[] { new ItemStack(input) }, new ItemStack[] { recipe.getResult() }); registerRecipe(4, new ItemStack[] { new ItemStack(input) }, new ItemStack[] { recipe.getResult() });
} }
} }

View File

@ -227,16 +227,14 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
} }
private @Nonnull ItemStack getFilledBucket(@Nonnull Block fluid) { private @Nonnull ItemStack getFilledBucket(@Nonnull Block fluid) {
switch (fluid.getType()) { return switch (fluid.getType()) {
case LAVA: case LAVA -> new ItemStack(Material.LAVA_BUCKET);
return new ItemStack(Material.LAVA_BUCKET); case WATER,
case WATER: BUBBLE_COLUMN -> new ItemStack(Material.WATER_BUCKET);
case BUBBLE_COLUMN: default ->
return new ItemStack(Material.WATER_BUCKET);
default:
// Fallback for any new liquids // Fallback for any new liquids
return new ItemStack(Material.BUCKET); new ItemStack(Material.BUCKET);
} };
} }
/** /**
@ -251,9 +249,8 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
if (block.isLiquid()) { if (block.isLiquid()) {
BlockData data = block.getBlockData(); BlockData data = block.getBlockData();
if (data instanceof Levelled) { if (data instanceof Levelled levelled) {
// Check if this is a full block. // Check if this is a full block.
Levelled levelled = (Levelled) data;
return levelled.getLevel() == 0; return levelled.getLevel() == 0;
} }
} }

View File

@ -62,7 +62,7 @@ public class AnimalGrowthAccelerator extends AbstractGrowthAccelerator {
} }
private boolean isReadyToGrow(Entity n) { private boolean isReadyToGrow(Entity n) {
return n instanceof Ageable && n.isValid() && !((Ageable) n).isAdult(); return n instanceof Ageable ageable && n.isValid() && !ageable.isAdult();
} }
} }

View File

@ -128,9 +128,7 @@ public class AutoBreeder extends SlimefunItem implements InventoryBlock, EnergyN
} }
private boolean canBreed(@Nonnull Entity n) { private boolean canBreed(@Nonnull Entity n) {
if (n.isValid() && n instanceof Animals) { if (n.isValid() && n instanceof Animals animal) {
Animals animal = (Animals) n;
return animal.isAdult() && animal.canBreed() && !animal.isLoveMode(); return animal.isAdult() && animal.canBreed() && !animal.isLoveMode();
} }

View File

@ -75,8 +75,8 @@ public class ProduceCollector extends AContainer implements RecipeDisplayItem {
// Mushroom Stew from Mooshrooms // Mushroom Stew from Mooshrooms
addProduce(new AnimalProduce(new ItemStack(Material.BOWL), new ItemStack(Material.MUSHROOM_STEW), n -> { addProduce(new AnimalProduce(new ItemStack(Material.BOWL), new ItemStack(Material.MUSHROOM_STEW), n -> {
if (n instanceof MushroomCow) { if (n instanceof MushroomCow mushroomCow) {
return ((MushroomCow) n).isAdult(); return mushroomCow.isAdult();
} else { } else {
return false; return false;
} }
@ -158,8 +158,8 @@ public class ProduceCollector extends AContainer implements RecipeDisplayItem {
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
private boolean isValidAnimal(Entity n, Predicate<LivingEntity> predicate) { private boolean isValidAnimal(Entity n, Predicate<LivingEntity> predicate) {
if (n instanceof LivingEntity) { if (n instanceof LivingEntity livingEntity) {
return predicate.test((LivingEntity) n); return predicate.test(livingEntity);
} else { } else {
return false; return false;
} }

View File

@ -44,8 +44,8 @@ public abstract class NetherStarReactor extends Reactor {
public void extraTick(@Nonnull Location l) { public void extraTick(@Nonnull Location l) {
Slimefun.runSync(() -> { Slimefun.runSync(() -> {
for (Entity entity : l.getWorld().getNearbyEntities(l, 5, 5, 5, n -> n instanceof LivingEntity && n.isValid())) { for (Entity entity : l.getWorld().getNearbyEntities(l, 5, 5, 5, n -> n instanceof LivingEntity && n.isValid())) {
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity livingEntity) {
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 60, 1)); livingEntity.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 60, 1));
} }
} }
}); });