From 05cff5225997bc8623bd71a24e6d6eb60b1883af Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Sun, 28 Apr 2024 10:01:45 -0500 Subject: [PATCH] Make use of new switch statements to allow cleaning up some of our chained instance of if else statements --- .../inputs/BoxedChemicalInputHandler.java | 33 ++-- .../mekanism/api/text/TextComponentUtil.java | 52 ++---- .../mekanism/client/gui/GuiFilterHolder.java | 13 +- .../client/gui/element/GuiElement.java | 17 +- .../gui/element/bar/GuiChemicalBar.java | 17 +- .../gui/element/button/FilterButton.java | 19 +- .../element/button/MovableFilterButton.java | 16 +- .../element/custom/GuiDictionaryTarget.java | 166 +++++++++--------- .../client/gui/qio/GuiQIOFilterHandler.java | 20 ++- .../emi/EmiStackUnderMouseProvider.java | 15 +- .../ChemicalCrystallizerRecipeCategory.java | 23 +-- .../holder/slot/InventorySlotHelper.java | 13 +- .../computer/BaseComputerHelper.java | 27 ++- .../computer/SpecialConverters.java | 31 ++-- .../lookingat/wthit/WTHITTooltipRenderer.java | 28 +-- .../container/MekanismContainer.java | 16 +- .../lookup/cache/type/ChemicalInputCache.java | 25 +-- .../lookup/cache/type/FluidInputCache.java | 25 +-- .../tile/component/TileComponentEjector.java | 30 ++-- .../tile/component/config/ConfigInfo.java | 24 ++- .../mekanism/common/util/ChemicalUtil.java | 36 ++-- 21 files changed, 304 insertions(+), 342 deletions(-) diff --git a/src/api/java/mekanism/api/recipes/inputs/BoxedChemicalInputHandler.java b/src/api/java/mekanism/api/recipes/inputs/BoxedChemicalInputHandler.java index 55ace3b4d83..fac3f056a93 100644 --- a/src/api/java/mekanism/api/recipes/inputs/BoxedChemicalInputHandler.java +++ b/src/api/java/mekanism/api/recipes/inputs/BoxedChemicalInputHandler.java @@ -71,27 +71,18 @@ public BoxedChemicalStack getRecipeInput(ChemicalStackIngredient recipeIng //All recipes currently require that we have an input. If we don't then return that we failed return BoxedChemicalStack.EMPTY; } - if (recipeIngredient instanceof GasStackIngredient ingredient) { - if (input.getChemicalType() == ChemicalType.GAS) { - return BoxedChemicalStack.box(ingredient.getMatchingInstance((GasStack) input.getChemicalStack())); - } - } else if (recipeIngredient instanceof InfusionStackIngredient ingredient) { - if (input.getChemicalType() == ChemicalType.INFUSION) { - return BoxedChemicalStack.box(ingredient.getMatchingInstance((InfusionStack) input.getChemicalStack())); - } - } else if (recipeIngredient instanceof PigmentStackIngredient ingredient) { - if (input.getChemicalType() == ChemicalType.PIGMENT) { - return BoxedChemicalStack.box(ingredient.getMatchingInstance((PigmentStack) input.getChemicalStack())); - } - } else if (recipeIngredient instanceof SlurryStackIngredient ingredient) { - if (input.getChemicalType() == ChemicalType.SLURRY) { - return BoxedChemicalStack.box(ingredient.getMatchingInstance((SlurryStack) input.getChemicalStack())); - } - } else { - throw new IllegalStateException("Unknown Chemical Type"); - } - //Something went wrong, input doesn't match types with ingredient - return BoxedChemicalStack.EMPTY; + return switch (recipeIngredient) { + case GasStackIngredient ingredient when input.getChemicalType() == ChemicalType.GAS -> + BoxedChemicalStack.box(ingredient.getMatchingInstance((GasStack) input.getChemicalStack())); + case InfusionStackIngredient ingredient when input.getChemicalType() == ChemicalType.INFUSION -> + BoxedChemicalStack.box(ingredient.getMatchingInstance((InfusionStack) input.getChemicalStack())); + case PigmentStackIngredient ingredient when input.getChemicalType() == ChemicalType.PIGMENT -> + BoxedChemicalStack.box(ingredient.getMatchingInstance((PigmentStack) input.getChemicalStack())); + case SlurryStackIngredient ingredient when input.getChemicalType() == ChemicalType.SLURRY -> + BoxedChemicalStack.box(ingredient.getMatchingInstance((SlurryStack) input.getChemicalStack())); + //Something went wrong, input doesn't match types with ingredient + default -> BoxedChemicalStack.EMPTY; + }; } /** diff --git a/src/api/java/mekanism/api/text/TextComponentUtil.java b/src/api/java/mekanism/api/text/TextComponentUtil.java index 6faf46b09d0..a576839cf17 100644 --- a/src/api/java/mekanism/api/text/TextComponentUtil.java +++ b/src/api/java/mekanism/api/text/TextComponentUtil.java @@ -59,43 +59,27 @@ public static MutableComponent build(Object... components) { continue; } MutableComponent current = null; - if (component instanceof IHasTextComponent hasTextComponent) { - current = hasTextComponent.getTextComponent().copy(); - } else if (component instanceof IHasTranslationKey hasTranslationKey) { - current = translate(hasTranslationKey.getTranslationKey()); - } else if (component instanceof EnumColor color) { - cachedStyle = cachedStyle.withColor(color.getColor()); - } else if (component instanceof TextColor color) { - cachedStyle = cachedStyle.withColor(color); - } else if (component instanceof Component c) { + switch (component) { + case IHasTextComponent hasTextComponent -> current = hasTextComponent.getTextComponent().copy(); + case IHasTranslationKey hasTranslationKey -> current = translate(hasTranslationKey.getTranslationKey()); + case EnumColor color -> cachedStyle = cachedStyle.withColor(color.getColor()); + case TextColor color -> cachedStyle = cachedStyle.withColor(color); //Just append if a text component is being passed - current = c.copy(); - } else if (component instanceof ChatFormatting formatting) { - cachedStyle = cachedStyle.applyFormat(formatting); - } else if (component instanceof ClickEvent event) { - cachedStyle = cachedStyle.withClickEvent(event); - } else if (component instanceof HoverEvent event) { - cachedStyle = cachedStyle.withHoverEvent(event); - } else if (component instanceof Block block) { - current = block.getName().copy(); - } else if (component instanceof Item item) { - current = item.getDescription().copy(); - } else if (component instanceof ItemStack stack) { - current = stack.getHoverName().copy(); - } else if (component instanceof FluidStack stack) { - current = stack.getHoverName().copy(); - } else if (component instanceof Fluid fluid) { - current = fluid.getFluidType().getDescription().copy(); - } else if (component instanceof EntityType entityType) { - current = entityType.getDescription().copy(); - } else if (component instanceof Direction direction) { - current = getTranslatedDirection(direction); - } else if (component instanceof Boolean bool) { - current = getTranslatedBoolean(bool); - } else { + case Component c -> current = c.copy(); + case ChatFormatting formatting -> cachedStyle = cachedStyle.applyFormat(formatting); + case ClickEvent event -> cachedStyle = cachedStyle.withClickEvent(event); + case HoverEvent event -> cachedStyle = cachedStyle.withHoverEvent(event); + case Block block -> current = block.getName().copy(); + case Item item -> current = item.getDescription().copy(); + case ItemStack stack -> current = stack.getHoverName().copy(); + case FluidStack stack -> current = stack.getHoverName().copy(); + case Fluid fluid -> current = fluid.getFluidType().getDescription().copy(); + case EntityType entityType -> current = entityType.getDescription().copy(); + case Direction direction -> current = getTranslatedDirection(direction); + case Boolean bool -> current = getTranslatedBoolean(bool); //Fallback to a generic replacement // this handles strings, numbers, and any type we don't necessarily know about - current = getString(component.toString()); + default -> current = getString(component.toString()); } if (current == null) { //If we don't have a component to add, don't diff --git a/src/main/java/mekanism/client/gui/GuiFilterHolder.java b/src/main/java/mekanism/client/gui/GuiFilterHolder.java index d5359dbba2c..ad3e16af2b0 100644 --- a/src/main/java/mekanism/client/gui/GuiFilterHolder.java +++ b/src/main/java/mekanism/client/gui/GuiFilterHolder.java @@ -71,13 +71,12 @@ protected void addGuiElements() { private List getRenderStacks(@Nullable IFilter filter) { if (filter != null) { - if (filter instanceof IItemStackFilter itemFilter) { - return List.of(itemFilter.getItemStack()); - } else if (filter instanceof ITagFilter tagFilter) { - return getTagStacks(tagFilter.getTagName()); - } else if (filter instanceof IModIDFilter modIDFilter) { - return getModIDStacks(modIDFilter.getModID()); - } + return switch (filter) { + case IItemStackFilter itemFilter -> List.of(itemFilter.getItemStack()); + case ITagFilter tagFilter -> getTagStacks(tagFilter.getTagName()); + case IModIDFilter modIDFilter -> getModIDStacks(modIDFilter.getModID()); + default -> Collections.emptyList(); + }; } return Collections.emptyList(); } diff --git a/src/main/java/mekanism/client/gui/element/GuiElement.java b/src/main/java/mekanism/client/gui/element/GuiElement.java index 674b4e1de1d..dbe323b1249 100644 --- a/src/main/java/mekanism/client/gui/element/GuiElement.java +++ b/src/main/java/mekanism/client/gui/element/GuiElement.java @@ -393,17 +393,12 @@ public ComponentPath nextFocusPath(@NotNull FocusNavigationEvent event) { return null; } if (!isFocused()) { - if (event instanceof ArrowNavigation) { - if (supportsArrowNavigation()) { - return ComponentPath.leaf(this); - } - } else if (event instanceof TabNavigation) { - if (supportsTabNavigation()) { - return ComponentPath.leaf(this); - } - } else if (event instanceof InitialFocus) { - return ComponentPath.leaf(this); - } + return switch (event) { + case ArrowNavigation arrowNavigation when supportsArrowNavigation() -> ComponentPath.leaf(this); + case TabNavigation tabNavigation when supportsTabNavigation() -> ComponentPath.leaf(this); + case InitialFocus initialFocus -> ComponentPath.leaf(this); + default -> ContainerEventHandler.super.nextFocusPath(event); + }; } return ContainerEventHandler.super.nextFocusPath(event); } diff --git a/src/main/java/mekanism/client/gui/element/bar/GuiChemicalBar.java b/src/main/java/mekanism/client/gui/element/bar/GuiChemicalBar.java index 180925330a2..a07ef882b78 100644 --- a/src/main/java/mekanism/client/gui/element/bar/GuiChemicalBar.java +++ b/src/main/java/mekanism/client/gui/element/bar/GuiChemicalBar.java @@ -36,16 +36,13 @@ protected boolean isEmpty(STACK stack) { @Override protected TankType getType(STACK stack) { CHEMICAL type = getHandler().getStack().getChemical(); - if (type instanceof Gas) { - return TankType.GAS_TANK; - } else if (type instanceof InfuseType) { - return TankType.INFUSION_TANK; - } else if (type instanceof Pigment) { - return TankType.PIGMENT_TANK; - } else if (type instanceof Slurry) { - return TankType.SLURRY_TANK; - } - return null; + return switch (type) { + case Gas gas -> TankType.GAS_TANK; + case InfuseType infuseType -> TankType.INFUSION_TANK; + case Pigment pigment -> TankType.PIGMENT_TANK; + case Slurry slurry -> TankType.SLURRY_TANK; + default -> null; + }; } @Override diff --git a/src/main/java/mekanism/client/gui/element/button/FilterButton.java b/src/main/java/mekanism/client/gui/element/button/FilterButton.java index b36811641e8..4b2667cbca5 100644 --- a/src/main/java/mekanism/client/gui/element/button/FilterButton.java +++ b/src/main/java/mekanism/client/gui/element/button/FilterButton.java @@ -131,18 +131,13 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { slotDisplay.updateStackList(); prevFilter = filter; } - Component filterDescriptor; - if (filter instanceof IItemStackFilter item) { - filterDescriptor = item.getItemStack().getHoverName(); - } else if (filter instanceof ITagFilter tag) { - filterDescriptor = Component.literal(tag.getTagName()); - } else if (filter instanceof IModIDFilter modId) { - filterDescriptor = Component.literal(modId.getModID()); - } else if (filter instanceof OredictionificatorFilter oredictionificatorFilter) { - filterDescriptor = Component.literal(oredictionificatorFilter.getFilterText()); - } else { - filterDescriptor = Component.empty(); - } + Component filterDescriptor = switch (filter) { + case IItemStackFilter item -> item.getItemStack().getHoverName(); + case ITagFilter tag -> Component.literal(tag.getTagName()); + case IModIDFilter modId -> Component.literal(modId.getModID()); + case OredictionificatorFilter oredictionificatorFilter -> Component.literal(oredictionificatorFilter.getFilterText()); + case null, default -> Component.empty(); + }; drawFilterDescriptor(guiGraphics, filterDescriptor, relativeX, relativeY); if (filter instanceof SorterFilter sorterFilter) { diff --git a/src/main/java/mekanism/client/gui/element/button/MovableFilterButton.java b/src/main/java/mekanism/client/gui/element/button/MovableFilterButton.java index 96e3334e5b5..0efd44e8e90 100644 --- a/src/main/java/mekanism/client/gui/element/button/MovableFilterButton.java +++ b/src/main/java/mekanism/client/gui/element/button/MovableFilterButton.java @@ -79,16 +79,12 @@ private void updateButtonVisibility(@Nullable IFilter filter) { public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks); IFilter filter = getFilter(); - EnumColor color; - if (filter instanceof IItemStackFilter) { - color = EnumColor.INDIGO; - } else if (filter instanceof ITagFilter) { - color = EnumColor.BRIGHT_GREEN; - } else if (filter instanceof IModIDFilter) { - color = EnumColor.RED; - } else { - color = null; - } + EnumColor color = switch (filter) { + case IItemStackFilter stackFilter -> EnumColor.INDIGO; + case ITagFilter tagFilter -> EnumColor.BRIGHT_GREEN; + case IModIDFilter modIDFilter -> EnumColor.RED; + case null, default -> null; + }; if (color != null) { GuiUtils.fill(guiGraphics, getButtonX(), getButtonY(), getButtonWidth(), getButtonHeight(), MekanismRenderer.getColorARGB(color, 0.3F)); } diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiDictionaryTarget.java b/src/main/java/mekanism/client/gui/element/custom/GuiDictionaryTarget.java index 9fe481ef1eb..b422636067d 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiDictionaryTarget.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiDictionaryTarget.java @@ -124,94 +124,98 @@ public List getTags(DictionaryTagType type) { public void setTargetSlot(@Nullable Object newTarget) { //Clear cached tags tags.clear(); - if (newTarget == null) { - setTarget(null); - } else if (newTarget instanceof ItemStack itemStack) { - if (itemStack.isEmpty()) { - setTarget(null); - } else { - ItemStack stack = itemStack.copyWithCount(1); - setTarget(stack); - Item item = stack.getItem(); - tags.put(DictionaryTagType.ITEM, TagCache.getItemTags(stack)); - if (item instanceof BlockItem blockItem) { - Block block = blockItem.getBlock(); - tags.put(DictionaryTagType.BLOCK, TagCache.getTagsAsStrings(block.builtInRegistryHolder())); - if (block instanceof IHasTileEntity || block.defaultBlockState().hasBlockEntity()) { - tags.put(DictionaryTagType.BLOCK_ENTITY_TYPE, TagCache.getTileEntityTypeTags(block)); + switch (newTarget) { + case null -> setTarget(null); + case ItemStack itemStack -> { + if (itemStack.isEmpty()) { + setTarget(null); + } else { + ItemStack stack = itemStack.copyWithCount(1); + setTarget(stack); + Item item = stack.getItem(); + tags.put(DictionaryTagType.ITEM, TagCache.getItemTags(stack)); + if (item instanceof BlockItem blockItem) { + Block block = blockItem.getBlock(); + tags.put(DictionaryTagType.BLOCK, TagCache.getTagsAsStrings(block.builtInRegistryHolder())); + if (block instanceof IHasTileEntity || block.defaultBlockState().hasBlockEntity()) { + tags.put(DictionaryTagType.BLOCK_ENTITY_TYPE, TagCache.getTileEntityTypeTags(block)); + } } - } - //Entity type tags - if (item instanceof SpawnEggItem spawnEggItem) { - tags.put(DictionaryTagType.ENTITY_TYPE, TagCache.getTagsAsStrings(spawnEggItem.getType(stack).getTags())); - } - //Enchantment tags - ItemEnchantments enchantments = stack.getEnchantments(); - if (!enchantments.isEmpty()) { - tags.put(DictionaryTagType.ENCHANTMENT, TagCache.getTagsAsStrings(enchantments.keySet().stream().flatMap(Holder::tags).distinct())); - } - //Get any potion tags - PotionContents potionContents = itemStack.get(DataComponents.POTION_CONTENTS); - if (potionContents != null) { - potionContents.potion().ifPresent(potionHolder -> tags.put(DictionaryTagType.POTION, TagCache.getTagsAsStrings(potionHolder))); - Set effectTags = new HashSet<>(); - for (MobEffectInstance effect : potionContents.getAllEffects()) { - effectTags.addAll(TagCache.getTagsAsStrings(effect.getEffect().tags())); + //Entity type tags + if (item instanceof SpawnEggItem spawnEggItem) { + tags.put(DictionaryTagType.ENTITY_TYPE, TagCache.getTagsAsStrings(spawnEggItem.getType(stack).getTags())); } - tags.put(DictionaryTagType.MOB_EFFECT, List.copyOf(effectTags)); - } - //Get any attribute tags - ItemAttributeModifiers modifiers = itemStack.get(DataComponents.ATTRIBUTE_MODIFIERS); - if (modifiers != null && !modifiers.modifiers().isEmpty()) { - //Only add them though if it has any attributes at all - tags.put(DictionaryTagType.ATTRIBUTE, TagCache.getTagsAsStrings(modifiers.modifiers().stream() - .flatMap(attribute -> attribute.attribute().tags()) - .distinct() - )); - } - //Get tags of any contained fluids - IFluidHandlerItem fluidHandler = Capabilities.FLUID.getCapability(stack); - if (fluidHandler != null) { - tags.put(DictionaryTagType.FLUID, TagCache.getTagsAsStrings(IntStream.range(0, fluidHandler.getTanks()) - .mapToObj(fluidHandler::getFluidInTank) - .filter(fluidInTank -> !fluidInTank.isEmpty()) - .flatMap(FluidStack::getTags) - .distinct() - )); + //Enchantment tags + ItemEnchantments enchantments = stack.getEnchantments(); + if (!enchantments.isEmpty()) { + tags.put(DictionaryTagType.ENCHANTMENT, TagCache.getTagsAsStrings(enchantments.keySet().stream().flatMap(Holder::tags).distinct())); + } + //Get any potion tags + PotionContents potionContents = itemStack.get(DataComponents.POTION_CONTENTS); + if (potionContents != null) { + potionContents.potion().ifPresent(potionHolder -> tags.put(DictionaryTagType.POTION, TagCache.getTagsAsStrings(potionHolder))); + Set effectTags = new HashSet<>(); + for (MobEffectInstance effect : potionContents.getAllEffects()) { + effectTags.addAll(TagCache.getTagsAsStrings(effect.getEffect().tags())); + } + tags.put(DictionaryTagType.MOB_EFFECT, List.copyOf(effectTags)); + } + //Get any attribute tags + ItemAttributeModifiers modifiers = itemStack.get(DataComponents.ATTRIBUTE_MODIFIERS); + if (modifiers != null && !modifiers.modifiers().isEmpty()) { + //Only add them though if it has any attributes at all + tags.put(DictionaryTagType.ATTRIBUTE, TagCache.getTagsAsStrings(modifiers.modifiers().stream() + .flatMap(attribute -> attribute.attribute().tags()) + .distinct() + )); + } + //Get tags of any contained fluids + IFluidHandlerItem fluidHandler = Capabilities.FLUID.getCapability(stack); + if (fluidHandler != null) { + tags.put(DictionaryTagType.FLUID, TagCache.getTagsAsStrings(IntStream.range(0, fluidHandler.getTanks()) + .mapToObj(fluidHandler::getFluidInTank) + .filter(fluidInTank -> !fluidInTank.isEmpty()) + .flatMap(FluidStack::getTags) + .distinct() + )); + } + //Get tags of any contained chemicals + addChemicalTags(DictionaryTagType.GAS, stack, Capabilities.GAS.item()); + addChemicalTags(DictionaryTagType.INFUSE_TYPE, stack, Capabilities.INFUSION.item()); + addChemicalTags(DictionaryTagType.PIGMENT, stack, Capabilities.PIGMENT.item()); + addChemicalTags(DictionaryTagType.SLURRY, stack, Capabilities.SLURRY.item()); + //TODO: Support other types of things? } - //Get tags of any contained chemicals - addChemicalTags(DictionaryTagType.GAS, stack, Capabilities.GAS.item()); - addChemicalTags(DictionaryTagType.INFUSE_TYPE, stack, Capabilities.INFUSION.item()); - addChemicalTags(DictionaryTagType.PIGMENT, stack, Capabilities.PIGMENT.item()); - addChemicalTags(DictionaryTagType.SLURRY, stack, Capabilities.SLURRY.item()); - //TODO: Support other types of things? } - } else if (newTarget instanceof FluidStack fluidStack) { - if (fluidStack.isEmpty()) { - setTarget(null); - } else { - setTarget(fluidStack.copy()); - tags.put(DictionaryTagType.FLUID, TagCache.getTagsAsStrings(fluidStack.getFluidHolder())); + case FluidStack fluidStack -> { + if (fluidStack.isEmpty()) { + setTarget(null); + } else { + setTarget(fluidStack.copy()); + tags.put(DictionaryTagType.FLUID, TagCache.getTagsAsStrings(fluidStack.getFluidHolder())); + } } - } else if (newTarget instanceof ChemicalStack chemicalStack) { - if (chemicalStack.isEmpty()) { - setTarget(null); - } else { - setTarget(chemicalStack.copy()); - List chemicalTags = TagCache.getTagsAsStrings(((ChemicalStack) target).getChemical().getTags()); - if (target instanceof GasStack) { - tags.put(DictionaryTagType.GAS, chemicalTags); - } else if (target instanceof InfusionStack) { - tags.put(DictionaryTagType.INFUSE_TYPE, chemicalTags); - } else if (target instanceof PigmentStack) { - tags.put(DictionaryTagType.PIGMENT, chemicalTags); - } else if (target instanceof SlurryStack) { - tags.put(DictionaryTagType.SLURRY, chemicalTags); + case ChemicalStack chemicalStack -> { + if (chemicalStack.isEmpty()) { + setTarget(null); + } else { + setTarget(chemicalStack.copy()); + List chemicalTags = TagCache.getTagsAsStrings(((ChemicalStack) target).getChemical().getTags()); + if (target instanceof GasStack) { + tags.put(DictionaryTagType.GAS, chemicalTags); + } else if (target instanceof InfusionStack) { + tags.put(DictionaryTagType.INFUSE_TYPE, chemicalTags); + } else if (target instanceof PigmentStack) { + tags.put(DictionaryTagType.PIGMENT, chemicalTags); + } else if (target instanceof SlurryStack) { + tags.put(DictionaryTagType.SLURRY, chemicalTags); + } } } - } else { - Mekanism.logger.warn("Unable to get tags for unknown type: {}", newTarget); - return; + default -> { + Mekanism.logger.warn("Unable to get tags for unknown type: {}", newTarget); + return; + } } //Update the list being viewed tagSetter.accept(tags.keySet()); diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIOFilterHandler.java b/src/main/java/mekanism/client/gui/qio/GuiQIOFilterHandler.java index e159003f20b..6d24ef3551a 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIOFilterHandler.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIOFilterHandler.java @@ -107,16 +107,18 @@ protected void addGuiElements() { } }, this::onClick, index -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.TOGGLE_FILTER_STATE, tile, index)), filter -> { if (filter != null) { - if (filter instanceof IItemStackFilter itemFilter) { - return List.of(itemFilter.getItemStack()); - } else if (filter instanceof ITagFilter tagFilter) { - String name = tagFilter.getTagName(); - if (name != null && !name.isEmpty()) { - return TagCache.getItemTagStacks(tagFilter.getTagName()); + return switch (filter) { + case IItemStackFilter itemFilter -> List.of(itemFilter.getItemStack()); + case ITagFilter tagFilter -> { + String name = tagFilter.getTagName(); + if (name != null && !name.isEmpty()) { + yield TagCache.getItemTagStacks(tagFilter.getTagName()); + } + yield Collections.emptyList(); } - } else if (filter instanceof IModIDFilter modIDFilter) { - return TagCache.getItemModIDStacks(modIDFilter.getModID()); - } + case IModIDFilter modIDFilter -> TagCache.getItemModIDStacks(modIDFilter.getModID()); + default -> Collections.emptyList(); + }; } return Collections.emptyList(); })); diff --git a/src/main/java/mekanism/client/recipe_viewer/emi/EmiStackUnderMouseProvider.java b/src/main/java/mekanism/client/recipe_viewer/emi/EmiStackUnderMouseProvider.java index 5904caa8eeb..01bd7497f7c 100644 --- a/src/main/java/mekanism/client/recipe_viewer/emi/EmiStackUnderMouseProvider.java +++ b/src/main/java/mekanism/client/recipe_viewer/emi/EmiStackUnderMouseProvider.java @@ -18,14 +18,13 @@ public EmiStackInteraction getStackAt(Screen screen, int x, int y) { if (screen instanceof GuiMekanism gui) { return GuiElementHandler.getClickableIngredientUnderMouse(gui, x, y, (helper, ingredient) -> { EmiStack emiStack; - if (ingredient instanceof ItemStack stack) { - emiStack = EmiStack.of(stack); - } else if (ingredient instanceof FluidStack stack) { - emiStack = NeoForgeEmiStack.of(stack); - } else if (ingredient instanceof ChemicalStack stack) { - emiStack = ChemicalEmiStack.create(stack); - } else { - return null; + switch (ingredient) { + case ItemStack stack -> emiStack = EmiStack.of(stack); + case FluidStack stack -> emiStack = NeoForgeEmiStack.of(stack); + case ChemicalStack stack -> emiStack = ChemicalEmiStack.create(stack); + default -> { + return null; + } } return new EmiStackInteraction(emiStack, null, false); }).orElse(EmiStackInteraction.EMPTY); diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java index 45e1d8418e5..af03434504d 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java @@ -80,17 +80,18 @@ public void setRecipe(@NotNull IRecipeLayoutBuilder builder, RecipeHolder input = recipe.getInput(); - if (input instanceof GasStackIngredient ingredient) { - initChemical(builder, MekanismJEI.TYPE_GAS, ingredient); - } else if (input instanceof InfusionStackIngredient ingredient) { - initChemical(builder, MekanismJEI.TYPE_INFUSION, ingredient); - } else if (input instanceof PigmentStackIngredient ingredient) { - initChemical(builder, MekanismJEI.TYPE_PIGMENT, ingredient); - } else if (input instanceof SlurryStackIngredient ingredient) { - initChemical(builder, MekanismJEI.TYPE_SLURRY, ingredient); - List displayItems = RecipeViewerUtils.getDisplayItems(ingredient); - if (!displayItems.isEmpty()) { - initItem(builder, RecipeIngredientRole.RENDER_ONLY, slurryOreSlot, displayItems).setSlotName(DISPLAYED_ITEM); + switch (input) { + case GasStackIngredient ingredient -> initChemical(builder, MekanismJEI.TYPE_GAS, ingredient); + case InfusionStackIngredient ingredient -> initChemical(builder, MekanismJEI.TYPE_INFUSION, ingredient); + case PigmentStackIngredient ingredient -> initChemical(builder, MekanismJEI.TYPE_PIGMENT, ingredient); + case SlurryStackIngredient ingredient -> { + initChemical(builder, MekanismJEI.TYPE_SLURRY, ingredient); + List displayItems = RecipeViewerUtils.getDisplayItems(ingredient); + if (!displayItems.isEmpty()) { + initItem(builder, RecipeIngredientRole.RENDER_ONLY, slurryOreSlot, displayItems).setSlotName(DISPLAYED_ITEM); + } + } + default -> { } } } diff --git a/src/main/java/mekanism/common/capabilities/holder/slot/InventorySlotHelper.java b/src/main/java/mekanism/common/capabilities/holder/slot/InventorySlotHelper.java index 442354a65d7..a9c2118a1f5 100644 --- a/src/main/java/mekanism/common/capabilities/holder/slot/InventorySlotHelper.java +++ b/src/main/java/mekanism/common/capabilities/holder/slot/InventorySlotHelper.java @@ -39,14 +39,11 @@ public SLOT addSlot(@NotNull SLOT slot) { if (built) { throw new IllegalStateException("Builder has already built."); } - if (slotHolder instanceof InventorySlotHolder slotHolder) { - slotHolder.addSlot(slot); - } else if (slotHolder instanceof ReadOnlyInventorySlotHolder slotHolder) { - slotHolder.addSlot(slot); - } else if (slotHolder instanceof ConfigInventorySlotHolder slotHolder) { - slotHolder.addSlot(slot); - } else { - throw new IllegalArgumentException("Holder does not know how to add slots"); + switch (slotHolder) { + case InventorySlotHolder inventorySlotHolder -> inventorySlotHolder.addSlot(slot); + case ReadOnlyInventorySlotHolder inventorySlotHolder -> inventorySlotHolder.addSlot(slot); + case ConfigInventorySlotHolder inventorySlotHolder -> inventorySlotHolder.addSlot(slot); + default -> throw new IllegalArgumentException("Holder does not know how to add slots"); } return slot; } diff --git a/src/main/java/mekanism/common/integration/computer/BaseComputerHelper.java b/src/main/java/mekanism/common/integration/computer/BaseComputerHelper.java index 824d0cf7c22..1790c0d96ad 100644 --- a/src/main/java/mekanism/common/integration/computer/BaseComputerHelper.java +++ b/src/main/java/mekanism/common/integration/computer/BaseComputerHelper.java @@ -1,6 +1,5 @@ package mekanism.common.integration.computer; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -42,8 +41,6 @@ import net.minecraft.core.Vec3i; import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtUtils; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -347,19 +344,21 @@ protected Map convertFilterCommon(IFilter result) { Map wrapped = new HashMap<>(); wrapped.put("type", convert(result.getFilterType())); wrapped.put("enabled", result.isEnabled()); - if (result instanceof IItemStackFilter itemFilter) { - ItemStack stack = itemFilter.getItemStack(); - wrapped.put("item", convert(stack.getItem())); - if (!stack.isEmpty()) { - DataComponentMap components = stack.getComponents(); - if (!components.isEmpty()) { - wrapped.put("itemComponents", SpecialConverters.wrapComponents(components)); + switch (result) { + case IItemStackFilter itemFilter -> { + ItemStack stack = itemFilter.getItemStack(); + wrapped.put("item", convert(stack.getItem())); + if (!stack.isEmpty()) { + DataComponentMap components = stack.getComponents(); + if (!components.isEmpty()) { + wrapped.put("itemComponents", SpecialConverters.wrapComponents(components)); + } } } - } else if (result instanceof IModIDFilter modIDFilter) { - wrapped.put("modId", modIDFilter.getModID()); - } else if (result instanceof ITagFilter tagFilter) { - wrapped.put("tag", tagFilter.getTagName()); + case IModIDFilter modIDFilter -> wrapped.put("modId", modIDFilter.getModID()); + case ITagFilter tagFilter -> wrapped.put("tag", tagFilter.getTagName()); + default -> { + } } return wrapped; } diff --git a/src/main/java/mekanism/common/integration/computer/SpecialConverters.java b/src/main/java/mekanism/common/integration/computer/SpecialConverters.java index 0a11369562e..192dcd2b7f4 100644 --- a/src/main/java/mekanism/common/integration/computer/SpecialConverters.java +++ b/src/main/java/mekanism/common/integration/computer/SpecialConverters.java @@ -1,6 +1,5 @@ package mekanism.common.integration.computer; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -22,7 +21,6 @@ import mekanism.common.util.text.InputValidator; import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.NbtUtils; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -126,21 +124,20 @@ public static > FILTER convertMapToFilter(@NotNul if (enabled instanceof Boolean enable) { filter.setEnabled(enable); } - if (filter instanceof IItemStackFilter itemFilter) { - decodeItemStackFilter(map, itemFilter); - } else if (filter instanceof IModIDFilter modIDFilter) { - decodeModIdFilter(map, modIDFilter); - } else if (filter instanceof ITagFilter tagFilter) { - decodeTagFilter(map, tagFilter); - } - if (filter instanceof MinerFilter minerFilter) { - decodeMinerFilter(map, minerFilter); - } else if (filter instanceof SorterFilter sorterFilter) { - decodeSorterFilter(map, sorterFilter); - } else if (filter instanceof QIOFilter qioFilter) { - decodeQioFilter(map, qioFilter); - } else if (filter instanceof OredictionificatorFilter oredictionificatorFilter) { - decodeOreDictFilter(map, oredictionificatorFilter); + switch (filter) { + case IItemStackFilter itemFilter -> decodeItemStackFilter(map, itemFilter); + case IModIDFilter modIDFilter -> decodeModIdFilter(map, modIDFilter); + case ITagFilter tagFilter -> decodeTagFilter(map, tagFilter); + default -> { + } + } + switch (filter) { + case MinerFilter minerFilter -> decodeMinerFilter(map, minerFilter); + case SorterFilter sorterFilter -> decodeSorterFilter(map, sorterFilter); + case QIOFilter qioFilter -> decodeQioFilter(map, qioFilter); + case OredictionificatorFilter oredictionificatorFilter -> decodeOreDictFilter(map, oredictionificatorFilter); + default -> { + } } return expectedType.cast(filter); } diff --git a/src/main/java/mekanism/common/integration/lookingat/wthit/WTHITTooltipRenderer.java b/src/main/java/mekanism/common/integration/lookingat/wthit/WTHITTooltipRenderer.java index a7989c0840b..fa54739afdc 100644 --- a/src/main/java/mekanism/common/integration/lookingat/wthit/WTHITTooltipRenderer.java +++ b/src/main/java/mekanism/common/integration/lookingat/wthit/WTHITTooltipRenderer.java @@ -43,26 +43,26 @@ private void append(ITooltip tooltip, IDataReader dataReader, IPluginConfig conf //Copy the data we need and have from the server and pass it on to the tooltip rendering for (Object element : helper.elements) { ResourceLocation name; - if (element instanceof Component component) { - if (lastText != null) { - //Fallback to printing the last text - tooltip.addLine(lastText); + switch (element) { + case Component component -> { + if (lastText != null) { + //Fallback to printing the last text + tooltip.addLine(lastText); + } + lastText = component; + continue; } - lastText = component; - continue; - } else if (element instanceof EnergyElement) { - name = LookingAtUtils.ENERGY; - } else if (element instanceof FluidElement) { - name = LookingAtUtils.FLUID; - } else if (element instanceof ChemicalElement chemicalElement) { - name = switch (chemicalElement.getChemicalType()) { + case EnergyElement energyElement -> name = LookingAtUtils.ENERGY; + case FluidElement fluidElement -> name = LookingAtUtils.FLUID; + case ChemicalElement chemicalElement -> name = switch (chemicalElement.getChemicalType()) { case GAS -> LookingAtUtils.GAS; case INFUSION -> LookingAtUtils.INFUSE_TYPE; case PIGMENT -> LookingAtUtils.PIGMENT; case SLURRY -> LookingAtUtils.SLURRY; }; - } else { - continue; + default -> { + continue; + } } if (config.getBoolean(name)) { tooltip.addLine(new MekElement(lastText, (LookingAtElement) element)); diff --git a/src/main/java/mekanism/common/inventory/container/MekanismContainer.java b/src/main/java/mekanism/common/inventory/container/MekanismContainer.java index 54179081ae6..46e4f205da5 100644 --- a/src/main/java/mekanism/common/inventory/container/MekanismContainer.java +++ b/src/main/java/mekanism/common/inventory/container/MekanismContainer.java @@ -641,16 +641,12 @@ public > void handleWindowProperty(short property public void handleWindowProperty(short property, byte[] value) { ISyncableData data = getTrackedData(property); - if (data instanceof SyncableByteArray syncable) { - syncable.set(value); - } else if (data instanceof SyncableFrequency syncable) { - syncable.set(getLevel().registryAccess(), value); - } else if (data instanceof SyncableList syncable) { - syncable.set(getLevel().registryAccess(), value); - } else if (data instanceof SyncableCollection syncable) { - syncable.set(getLevel().registryAccess(), value); - } else { - Mekanism.logger.error("Unknown byte value type: {}, please report", data.getClass().getName()); + switch (data) { + case SyncableByteArray syncable -> syncable.set(value); + case SyncableFrequency syncable -> syncable.set(getLevel().registryAccess(), value); + case SyncableList syncable -> syncable.set(getLevel().registryAccess(), value); + case SyncableCollection syncable -> syncable.set(getLevel().registryAccess(), value); + default -> Mekanism.logger.error("Unknown byte value type: {}, please report", data.getClass().getName()); } } diff --git a/src/main/java/mekanism/common/recipe/lookup/cache/type/ChemicalInputCache.java b/src/main/java/mekanism/common/recipe/lookup/cache/type/ChemicalInputCache.java index 7b652689fd8..1d64d1db43d 100644 --- a/src/main/java/mekanism/common/recipe/lookup/cache/type/ChemicalInputCache.java +++ b/src/main/java/mekanism/common/recipe/lookup/cache/type/ChemicalInputCache.java @@ -14,18 +14,21 @@ public class ChemicalInputCache, STACK exten @Override public boolean mapInputs(RECIPE recipe, ChemicalStackIngredient inputIngredient) { - if (inputIngredient instanceof SingleChemicalStackIngredient single) { - addInputCache(single.getInputRaw(), recipe); - } else if (inputIngredient instanceof TaggedChemicalStackIngredient tagged) { - for (Holder input : tagged.getRawInput()) { - addInputCache(input, recipe); + switch (inputIngredient) { + case SingleChemicalStackIngredient single -> addInputCache(single.getInputRaw(), recipe); + case TaggedChemicalStackIngredient tagged -> { + for (Holder input : tagged.getRawInput()) { + addInputCache(input, recipe); + } + } + case MultiChemicalStackIngredient multi -> { + return mapMultiInputs(recipe, multi); + } + default -> { + //This should never really happen as we don't really allow for custom ingredients especially for networking, + // but if it does add it as a fallback + return true; } - } else if (inputIngredient instanceof MultiChemicalStackIngredient multi) { - return mapMultiInputs(recipe, multi); - } else { - //This should never really happen as we don't really allow for custom ingredients especially for networking, - // but if it does add it as a fallback - return true; } return false; } diff --git a/src/main/java/mekanism/common/recipe/lookup/cache/type/FluidInputCache.java b/src/main/java/mekanism/common/recipe/lookup/cache/type/FluidInputCache.java index 4918f1572a7..cdc4db70ebc 100644 --- a/src/main/java/mekanism/common/recipe/lookup/cache/type/FluidInputCache.java +++ b/src/main/java/mekanism/common/recipe/lookup/cache/type/FluidInputCache.java @@ -13,18 +13,21 @@ public class FluidInputCache extends NBTSensitive @Override public boolean mapInputs(RECIPE recipe, FluidStackIngredient inputIngredient) { - if (inputIngredient instanceof SingleFluidStackIngredient single) { - addNbtInputCache(single.getInputRaw(), recipe); - } else if (inputIngredient instanceof TaggedFluidStackIngredient tagged) { - for (Holder input : tagged.getRawInput()) { - addInputCache(input, recipe); + switch (inputIngredient) { + case SingleFluidStackIngredient single -> addNbtInputCache(single.getInputRaw(), recipe); + case TaggedFluidStackIngredient tagged -> { + for (Holder input : tagged.getRawInput()) { + addInputCache(input, recipe); + } + } + case MultiFluidStackIngredient multi -> { + return mapMultiInputs(recipe, multi); + } + default -> { + //This should never really happen as we don't really allow for custom ingredients especially for networking, + // but if it does add it as a fallback + return true; } - } else if (inputIngredient instanceof MultiFluidStackIngredient multi) { - return mapMultiInputs(recipe, multi); - } else { - //This should never really happen as we don't really allow for custom ingredients especially for networking, - // but if it does add it as a fallback - return true; } return false; } diff --git a/src/main/java/mekanism/common/tile/component/TileComponentEjector.java b/src/main/java/mekanism/common/tile/component/TileComponentEjector.java index 3ef684c267d..8036543257a 100644 --- a/src/main/java/mekanism/common/tile/component/TileComponentEjector.java +++ b/src/main/java/mekanism/common/tile/component/TileComponentEjector.java @@ -190,24 +190,30 @@ private void eject(TransmissionType type, Direction facing, ConfigInfo info) { //Lazy init outputData, we use an identity hashmap to allow for cheaper compare checks outputData = new IdentityHashMap<>(); } - if (type.isChemical() && slotInfo instanceof ChemicalSlotInfo chemicalSlotInfo) { - for (IChemicalTank tank : chemicalSlotInfo.getTanks()) { - if (!tank.isEmpty() && (canTankEject == null || canTankEject.test(tank))) { - addData(outputData, tank, outputSides); + switch (slotInfo) { + case ChemicalSlotInfo chemicalSlotInfo when type.isChemical() -> { + for (IChemicalTank tank : chemicalSlotInfo.getTanks()) { + if (!tank.isEmpty() && (canTankEject == null || canTankEject.test(tank))) { + addData(outputData, tank, outputSides); + } } } - } else if (type == TransmissionType.FLUID && slotInfo instanceof FluidSlotInfo fluidSlotInfo) { - for (IExtendedFluidTank tank : fluidSlotInfo.getTanks()) { - if (!tank.isEmpty()) { - addData(outputData, tank, outputSides); + case FluidSlotInfo fluidSlotInfo when type == TransmissionType.FLUID -> { + for (IExtendedFluidTank tank : fluidSlotInfo.getTanks()) { + if (!tank.isEmpty()) { + addData(outputData, tank, outputSides); + } } } - } else if (type == TransmissionType.ENERGY && slotInfo instanceof EnergySlotInfo energySlotInfo) { - for (IEnergyContainer container : energySlotInfo.getContainers()) { - if (!container.isEmpty()) { - addData(outputData, container, outputSides); + case EnergySlotInfo energySlotInfo when type == TransmissionType.ENERGY -> { + for (IEnergyContainer container : energySlotInfo.getContainers()) { + if (!container.isEmpty()) { + addData(outputData, container, outputSides); + } } } + default -> { + } } } } diff --git a/src/main/java/mekanism/common/tile/component/config/ConfigInfo.java b/src/main/java/mekanism/common/tile/component/config/ConfigInfo.java index f4366679291..9eeae189f64 100644 --- a/src/main/java/mekanism/common/tile/component/config/ConfigInfo.java +++ b/src/main/java/mekanism/common/tile/component/config/ConfigInfo.java @@ -138,17 +138,23 @@ public void addSlotInfo(@NotNull DataType dataType, @NotNull ISlotInfo info) { supportedDataTypes.add(dataType); } // set up mapping - if (info instanceof ChemicalSlotInfo slotInfo) { - for (IChemicalTank tank : slotInfo.getTanks()) { - containerTypeMapping.computeIfAbsent(tank, t -> new ArrayList<>()).add(dataType); + switch (info) { + case ChemicalSlotInfo chemicalSlotInfo -> { + for (IChemicalTank tank : chemicalSlotInfo.getTanks()) { + containerTypeMapping.computeIfAbsent(tank, t -> new ArrayList<>()).add(dataType); + } } - } else if (info instanceof FluidSlotInfo slotInfo) { - for (IExtendedFluidTank tank : slotInfo.getTanks()) { - containerTypeMapping.computeIfAbsent(tank, t -> new ArrayList<>()).add(dataType); + case FluidSlotInfo fluidSlotInfo -> { + for (IExtendedFluidTank tank : fluidSlotInfo.getTanks()) { + containerTypeMapping.computeIfAbsent(tank, t -> new ArrayList<>()).add(dataType); + } } - } else if (info instanceof InventorySlotInfo slotInfo) { - for (IInventorySlot slot : slotInfo.getSlots()) { - containerTypeMapping.computeIfAbsent(slot, t -> new ArrayList<>()).add(dataType); + case InventorySlotInfo inventorySlotInfo -> { + for (IInventorySlot slot : inventorySlotInfo.getSlots()) { + containerTypeMapping.computeIfAbsent(slot, t -> new ArrayList<>()).add(dataType); + } + } + default -> { } } } diff --git a/src/main/java/mekanism/common/util/ChemicalUtil.java b/src/main/java/mekanism/common/util/ChemicalUtil.java index b42835004bc..eabf588efb4 100644 --- a/src/main/java/mekanism/common/util/ChemicalUtil.java +++ b/src/main/java/mekanism/common/util/ChemicalUtil.java @@ -102,17 +102,13 @@ public static ChemicalStack getEmptyStack(ChemicalType chemicalType) { */ @SuppressWarnings("unchecked") public static > STACK getEmptyStack(STACK stack) { - if (stack instanceof GasStack) { - return (STACK) GasStack.EMPTY; - } else if (stack instanceof InfusionStack) { - return (STACK) InfusionStack.EMPTY; - } else if (stack instanceof PigmentStack) { - return (STACK) PigmentStack.EMPTY; - } else if (stack instanceof SlurryStack) { - return (STACK) SlurryStack.EMPTY; - } else { - throw new IllegalStateException("Unknown Chemical Type: " + stack.getChemical().getClass().getName()); - } + return switch (stack) { + case GasStack gasStack -> (STACK) GasStack.EMPTY; + case InfusionStack infusionStack -> (STACK) InfusionStack.EMPTY; + case PigmentStack pigmentStack -> (STACK) PigmentStack.EMPTY; + case SlurryStack slurryStack -> (STACK) SlurryStack.EMPTY; + default -> throw new IllegalStateException("Unknown Chemical Type: " + stack.getChemical().getClass().getName()); + }; } /** @@ -195,17 +191,13 @@ private static ItemStack getEmptyChemicalTank(ChemicalTankTier tier) { } public static ItemStack getFilledVariant(ItemStack toFill, IChemicalProvider provider) { - if (provider instanceof IGasProvider gasProvider) { - return getFilledVariant(toFill, gasProvider, ContainerType.GAS); - } else if (provider instanceof IInfuseTypeProvider infuseTypeProvider) { - return getFilledVariant(toFill, infuseTypeProvider, ContainerType.INFUSION); - } else if (provider instanceof IPigmentProvider pigmentProvider) { - return getFilledVariant(toFill, pigmentProvider, ContainerType.PIGMENT); - } else if (provider instanceof ISlurryProvider slurryProvider) { - return getFilledVariant(toFill, slurryProvider, ContainerType.SLURRY); - } else { - throw new IllegalStateException("Unknown Chemical Type: " + provider.getChemical().getClass().getName()); - } + return switch (provider) { + case IGasProvider gasProvider -> getFilledVariant(toFill, gasProvider, ContainerType.GAS); + case IInfuseTypeProvider infuseTypeProvider -> getFilledVariant(toFill, infuseTypeProvider, ContainerType.INFUSION); + case IPigmentProvider pigmentProvider -> getFilledVariant(toFill, pigmentProvider, ContainerType.PIGMENT); + case ISlurryProvider slurryProvider -> getFilledVariant(toFill, slurryProvider, ContainerType.SLURRY); + default -> throw new IllegalStateException("Unknown Chemical Type: " + provider.getChemical().getClass().getName()); + }; } private static , STACK extends ChemicalStack, TANK extends IChemicalTank> ItemStack getFilledVariant(