Search in sources :

Example 1 with ChemicalStack

use of mekanism.api.chemical.ChemicalStack in project Mekanism by mekanism.

the class GuiDictionaryTarget method setTargetSlot.

public void setTargetSlot(Object newTarget, boolean playSound) {
    // Clear cached tags
    tags.clear();
    if (newTarget == null) {
        target = null;
    } else if (newTarget instanceof ItemStack) {
        ItemStack itemStack = (ItemStack) newTarget;
        if (itemStack.isEmpty()) {
            target = null;
        } else {
            ItemStack stack = StackUtils.size(itemStack, 1);
            target = stack;
            Item item = stack.getItem();
            tags.put(DictionaryTagType.ITEM, TagCache.getItemTags(stack));
            if (item instanceof BlockItem) {
                Block block = ((BlockItem) item).getBlock();
                tags.put(DictionaryTagType.BLOCK, TagCache.getTagsAsStrings(block.getTags()));
                if (block instanceof IHasTileEntity || block.hasTileEntity(block.defaultBlockState())) {
                    tags.put(DictionaryTagType.TILE_ENTITY_TYPE, TagCache.getTileEntityTypeTags(block));
                }
            }
            // Entity type tags
            if (item instanceof SpawnEggItem) {
                tags.put(DictionaryTagType.ENTITY_TYPE, TagCache.getTagsAsStrings(((SpawnEggItem) item).getType(stack.getTag()).getTags()));
            }
            // Enchantment tags
            Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
            if (!enchantments.isEmpty()) {
                Set<ResourceLocation> enchantmentTags = new HashSet<>();
                for (Enchantment enchantment : enchantments.keySet()) {
                    enchantmentTags.addAll(enchantment.getTags());
                }
                tags.put(DictionaryTagType.ENCHANTMENT, TagCache.getTagsAsStrings(enchantmentTags));
            }
            // Get any potion tags
            Potion potion = PotionUtils.getPotion(itemStack);
            if (potion != Potions.EMPTY) {
                tags.put(DictionaryTagType.POTION, TagCache.getTagsAsStrings(potion.getTags()));
            }
            // Get tags of any contained fluids
            FluidUtil.getFluidHandler(stack).ifPresent(fluidHandler -> {
                Set<ResourceLocation> fluidTags = new HashSet<>();
                for (int tank = 0; tank < fluidHandler.getTanks(); tank++) {
                    FluidStack fluidInTank = fluidHandler.getFluidInTank(tank);
                    if (!fluidInTank.isEmpty()) {
                        fluidTags.addAll(fluidInTank.getFluid().getTags());
                    }
                }
                tags.put(DictionaryTagType.FLUID, TagCache.getTagsAsStrings(fluidTags));
            });
            // Get tags of any contained chemicals
            addChemicalTags(DictionaryTagType.GAS, stack, Capabilities.GAS_HANDLER_CAPABILITY);
            addChemicalTags(DictionaryTagType.INFUSE_TYPE, stack, Capabilities.INFUSION_HANDLER_CAPABILITY);
            addChemicalTags(DictionaryTagType.PIGMENT, stack, Capabilities.PIGMENT_HANDLER_CAPABILITY);
            addChemicalTags(DictionaryTagType.SLURRY, stack, Capabilities.SLURRY_HANDLER_CAPABILITY);
        // TODO: Support other types of things?
        }
    } else if (newTarget instanceof FluidStack) {
        FluidStack fluidStack = (FluidStack) newTarget;
        if (fluidStack.isEmpty()) {
            target = null;
        } else {
            target = fluidStack.copy();
            tags.put(DictionaryTagType.FLUID, TagCache.getTagsAsStrings(((FluidStack) target).getFluid().getTags()));
        }
    } else if (newTarget instanceof ChemicalStack) {
        ChemicalStack<?> chemicalStack = (ChemicalStack<?>) newTarget;
        if (chemicalStack.isEmpty()) {
            target = null;
        } else {
            target = chemicalStack.copy();
            List<String> chemicalTags = TagCache.getTagsAsStrings(((ChemicalStack<?>) target).getType().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;
    }
    // Update the list being viewed
    tagSetter.accept(tags.keySet());
    if (playSound) {
        playClickSound();
    }
}
Also used : Enchantment(net.minecraft.enchantment.Enchantment) FluidUtil(net.minecraftforge.fluids.FluidUtil) ChemicalStack(mekanism.api.chemical.ChemicalStack) GuiElement(mekanism.client.gui.element.GuiElement) Item(net.minecraft.item.Item) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) HashSet(java.util.HashSet) FluidType(mekanism.client.render.MekanismRenderer.FluidType) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) Capabilities(mekanism.common.capabilities.Capabilities) Map(java.util.Map) IGuiWrapper(mekanism.client.gui.IGuiWrapper) GasStack(mekanism.api.chemical.gas.GasStack) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Nullable(javax.annotation.Nullable) PotionUtils(net.minecraft.potion.PotionUtils) Mekanism(mekanism.common.Mekanism) EnumMap(java.util.EnumMap) StackUtils(mekanism.common.util.StackUtils) Potions(net.minecraft.potion.Potions) Set(java.util.Set) IChemicalHandler(mekanism.api.chemical.IChemicalHandler) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) Capability(net.minecraftforge.common.capabilities.Capability) Consumer(java.util.function.Consumer) DictionaryTagType(mekanism.client.gui.item.GuiDictionary.DictionaryTagType) IJEIGhostTarget(mekanism.client.jei.interfaces.IJEIGhostTarget) List(java.util.List) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) Screen(net.minecraft.client.gui.screen.Screen) MekanismRenderer(mekanism.client.render.MekanismRenderer) BlockItem(net.minecraft.item.BlockItem) ResourceLocation(net.minecraft.util.ResourceLocation) PigmentStack(mekanism.api.chemical.pigment.PigmentStack) SpawnEggItem(net.minecraft.item.SpawnEggItem) TilingDirection(mekanism.client.gui.GuiUtils.TilingDirection) FluidStack(net.minecraftforge.fluids.FluidStack) TextComponentUtil(mekanism.api.text.TextComponentUtil) Collections(java.util.Collections) Potion(net.minecraft.potion.Potion) TagCache(mekanism.common.base.TagCache) PigmentStack(mekanism.api.chemical.pigment.PigmentStack) HashSet(java.util.HashSet) Set(java.util.Set) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) Potion(net.minecraft.potion.Potion) FluidStack(net.minecraftforge.fluids.FluidStack) BlockItem(net.minecraft.item.BlockItem) Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) SpawnEggItem(net.minecraft.item.SpawnEggItem) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) SpawnEggItem(net.minecraft.item.SpawnEggItem) Block(net.minecraft.block.Block) List(java.util.List) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) Map(java.util.Map) EnumMap(java.util.EnumMap) ChemicalStack(mekanism.api.chemical.ChemicalStack) SlurryStack(mekanism.api.chemical.slurry.SlurryStack)

Example 2 with ChemicalStack

use of mekanism.api.chemical.ChemicalStack in project Mekanism by mekanism.

the class CCArgumentWrapper method wrapReturnType.

private static Object wrapReturnType(Object result) {
    if (result == null || result instanceof Number || result instanceof Boolean || result instanceof String) {
        // Short circuit if it doesn't need wrapping
        return result;
    } else if (result instanceof ResourceLocation || result instanceof UUID) {
        return result.toString();
    } else if (result instanceof ForgeRegistryEntry<?>) {
        return getName((ForgeRegistryEntry<?>) result);
    } else if (result instanceof ChemicalStack<?>) {
        ChemicalStack<?> stack = (ChemicalStack<?>) result;
        Map<String, Object> wrapped = new HashMap<>(2);
        wrapped.put("name", getName(stack.getType()));
        wrapped.put("amount", stack.getAmount());
        return wrapped;
    } else if (result instanceof FluidStack) {
        FluidStack stack = (FluidStack) result;
        return wrapStack(stack.getFluid(), "amount", stack.getAmount(), stack.getTag());
    } else if (result instanceof ItemStack) {
        ItemStack stack = (ItemStack) result;
        return wrapStack(stack.getItem(), "count", stack.getCount(), stack.getTag());
    } else if (result instanceof INBT) {
        Object wrapped = wrapNBT((INBT) result);
        if (wrapped != null) {
            return wrapped;
        }
    } else if (result instanceof Vector3i) {
        // BlockPos is covered by this case
        Vector3i pos = (Vector3i) result;
        Map<String, Object> wrapped = new HashMap<>(3);
        wrapped.put("x", pos.getX());
        wrapped.put("y", pos.getY());
        wrapped.put("z", pos.getZ());
        return wrapped;
    } else if (result instanceof Coord4D) {
        // BlockPos is covered by this case
        Coord4D coord = (Coord4D) result;
        Map<String, Object> wrapped = new HashMap<>(4);
        wrapped.put("x", coord.getX());
        wrapped.put("y", coord.getY());
        wrapped.put("z", coord.getZ());
        wrapped.put("dimension", wrapReturnType(coord.dimension.location()));
        return wrapped;
    } else if (result instanceof Frequency) {
        FrequencyIdentity identity = ((Frequency) result).getIdentity();
        Map<String, Object> wrapped = new HashMap<>(2);
        wrapped.put("key", wrapReturnType(identity.getKey()));
        wrapped.put("public", identity.isPublic());
        return wrapped;
    } else if (result instanceof Enum) {
        return ((Enum<?>) result).name();
    } else if (result instanceof IFilter) {
        Map<String, Object> wrapped = new HashMap<>();
        wrapped.put("type", wrapReturnType(((IFilter<?>) result).getFilterType()));
        if (result instanceof IItemStackFilter) {
            ItemStack stack = ((IItemStackFilter<?>) result).getItemStack();
            wrapped.put("item", wrapReturnType(stack.getItem()));
            if (!stack.isEmpty()) {
                CompoundNBT tag = stack.getTag();
                if (tag != null && !tag.isEmpty()) {
                    wrapped.put("itemNBT", wrapNBT(tag));
                }
            }
        } else if (result instanceof IMaterialFilter) {
            wrapped.put("materialItem", wrapReturnType(((IMaterialFilter<?>) result).getMaterialItem().getItem()));
        } else if (result instanceof IModIDFilter) {
            wrapped.put("modId", ((IModIDFilter<?>) result).getModID());
        } else if (result instanceof ITagFilter) {
            wrapped.put("tag", ((ITagFilter<?>) result).getTagName());
        }
        if (result instanceof MinerFilter) {
            MinerFilter<?> minerFilter = (MinerFilter<?>) result;
            wrapped.put("requiresReplacement", minerFilter.requiresReplacement);
            wrapped.put("replaceTarget", wrapReturnType(minerFilter.replaceTarget));
        } else if (result instanceof SorterFilter) {
            SorterFilter<?> sorterFilter = (SorterFilter<?>) result;
            wrapped.put("allowDefault", sorterFilter.allowDefault);
            wrapped.put("color", wrapReturnType(sorterFilter.color));
            wrapped.put("size", sorterFilter.sizeMode);
            wrapped.put("min", sorterFilter.min);
            wrapped.put("max", sorterFilter.max);
            if (sorterFilter instanceof SorterItemStackFilter) {
                SorterItemStackFilter filter = (SorterItemStackFilter) sorterFilter;
                wrapped.put("fuzzy", filter.fuzzyMode);
            }
        } else if (result instanceof QIOFilter) {
            QIOFilter<?> qioFilter = (QIOFilter<?>) result;
            if (qioFilter instanceof QIOItemStackFilter) {
                QIOItemStackFilter filter = (QIOItemStackFilter) qioFilter;
                wrapped.put("fuzzy", filter.fuzzyMode);
            }
        } else if (result instanceof OredictionificatorFilter) {
            OredictionificatorFilter<?, ?, ?> filter = (OredictionificatorFilter<?, ?, ?>) result;
            wrapped.put("target", filter.getFilterText());
            wrapped.put("selected", wrapReturnType(filter.getResultElement()));
        }
        return wrapped;
    } else if (result instanceof Map) {
        return ((Map<?, ?>) result).entrySet().stream().collect(Collectors.toMap(entry -> wrapReturnType(entry.getKey()), entry -> wrapReturnType(entry.getValue()), (a, b) -> b));
    } else if (result instanceof Collection) {
        // so there is no real difference at that point about the type it is
        return ((Collection<?>) result).stream().map(CCArgumentWrapper::wrapReturnType).collect(Collectors.toList());
    } else if (result instanceof Object[]) {
        // Note: This doesn't handle/deal with primitive arrays
        return Arrays.stream((Object[]) result).map(CCArgumentWrapper::wrapReturnType).toArray();
    }
    return result;
}
Also used : SorterFilter(mekanism.common.content.transporter.SorterFilter) Arrays(java.util.Arrays) OredictionificatorFilter(mekanism.common.content.oredictionificator.OredictionificatorFilter) ByteArrayNBT(net.minecraft.nbt.ByteArrayNBT) ChemicalStack(mekanism.api.chemical.ChemicalStack) Item(net.minecraft.item.Item) BiFunction(java.util.function.BiFunction) Constants(net.minecraftforge.common.util.Constants) Frequency(mekanism.common.lib.frequency.Frequency) CompoundNBT(net.minecraft.nbt.CompoundNBT) FloatNBT(net.minecraft.nbt.FloatNBT) QIOItemStackFilter(mekanism.common.content.qio.filter.QIOItemStackFilter) InputValidator(mekanism.common.util.text.InputValidator) IArguments(dan200.computercraft.api.lua.IArguments) TileEntityOredictionificator(mekanism.common.tile.machine.TileEntityOredictionificator) Locale(java.util.Locale) Map(java.util.Map) QIOFilter(mekanism.common.content.qio.filter.QIOFilter) SorterFilter(mekanism.common.content.transporter.SorterFilter) ByteNBT(net.minecraft.nbt.ByteNBT) ListNBT(net.minecraft.nbt.ListNBT) ForgeRegistryEntry(net.minecraftforge.registries.ForgeRegistryEntry) FilterType(mekanism.common.content.filter.FilterType) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ITagFilter(mekanism.common.content.filter.ITagFilter) IntNBT(net.minecraft.nbt.IntNBT) BaseFilter(mekanism.common.content.filter.BaseFilter) IModIDFilter(mekanism.common.content.filter.IModIDFilter) Optional(java.util.Optional) Vector3i(net.minecraft.util.math.vector.Vector3i) FluidStack(net.minecraftforge.fluids.FluidStack) IFilter(mekanism.common.content.filter.IFilter) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) IntStream(java.util.stream.IntStream) MethodResult(dan200.computercraft.api.lua.MethodResult) EnumColor(mekanism.api.text.EnumColor) LuaException(dan200.computercraft.api.lua.LuaException) ComputerArgumentHandler(mekanism.common.integration.computer.ComputerArgumentHandler) HashMap(java.util.HashMap) OredictionificatorItemFilter(mekanism.common.content.oredictionificator.OredictionificatorItemFilter) ItemStack(net.minecraft.item.ItemStack) FloatingLong(mekanism.api.math.FloatingLong) BiConsumer(java.util.function.BiConsumer) NumberNBT(net.minecraft.nbt.NumberNBT) Nullable(javax.annotation.Nullable) INBT(net.minecraft.nbt.INBT) LongArrayNBT(net.minecraft.nbt.LongArrayNBT) StringNBT(net.minecraft.nbt.StringNBT) EndNBT(net.minecraft.nbt.EndNBT) DoubleNBT(net.minecraft.nbt.DoubleNBT) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting) IMaterialFilter(mekanism.common.content.filter.IMaterialFilter) CollectionNBT(net.minecraft.nbt.CollectionNBT) ShortNBT(net.minecraft.nbt.ShortNBT) MinerFilter(mekanism.common.content.miner.MinerFilter) Items(net.minecraft.item.Items) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) Coord4D(mekanism.api.Coord4D) SorterItemStackFilter(mekanism.common.content.transporter.SorterItemStackFilter) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) LongNBT(net.minecraft.nbt.LongNBT) ResourceLocation(net.minecraft.util.ResourceLocation) DoublePredicate(java.util.function.DoublePredicate) Collections(java.util.Collections) FrequencyIdentity(mekanism.common.lib.frequency.Frequency.FrequencyIdentity) HashMap(java.util.HashMap) FluidStack(net.minecraftforge.fluids.FluidStack) FrequencyIdentity(mekanism.common.lib.frequency.Frequency.FrequencyIdentity) QIOItemStackFilter(mekanism.common.content.qio.filter.QIOItemStackFilter) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) INBT(net.minecraft.nbt.INBT) SorterItemStackFilter(mekanism.common.content.transporter.SorterItemStackFilter) ResourceLocation(net.minecraft.util.ResourceLocation) Coord4D(mekanism.api.Coord4D) QIOFilter(mekanism.common.content.qio.filter.QIOFilter) UUID(java.util.UUID) ChemicalStack(mekanism.api.chemical.ChemicalStack) CompoundNBT(net.minecraft.nbt.CompoundNBT) IMaterialFilter(mekanism.common.content.filter.IMaterialFilter) MinerFilter(mekanism.common.content.miner.MinerFilter) ForgeRegistryEntry(net.minecraftforge.registries.ForgeRegistryEntry) ITagFilter(mekanism.common.content.filter.ITagFilter) IFilter(mekanism.common.content.filter.IFilter) Vector3i(net.minecraft.util.math.vector.Vector3i) Frequency(mekanism.common.lib.frequency.Frequency) OredictionificatorFilter(mekanism.common.content.oredictionificator.OredictionificatorFilter) Collection(java.util.Collection) ItemStack(net.minecraft.item.ItemStack) IModIDFilter(mekanism.common.content.filter.IModIDFilter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ChemicalStack

use of mekanism.api.chemical.ChemicalStack in project Mekanism by mekanism.

the class HwylaTooltipRenderer method draw.

@Override
public void draw(CompoundNBT data, ICommonAccessor accessor, int x, int y) {
    ListNBT list = data.getList(NBTConstants.MEK_DATA, NBT.TAG_COMPOUND);
    MatrixStack matrix = new MatrixStack();
    int currentX = x + 1;
    int currentY = y + 1;
    for (int i = 0; i < list.size(); i++) {
        CompoundNBT elementData = list.getCompound(i);
        LookingAtElement element;
        if (elementData.contains(MekanismHwylaPlugin.TEXT, NBT.TAG_STRING)) {
            ITextComponent text = ITextComponent.Serializer.fromJson(elementData.getString(MekanismHwylaPlugin.TEXT));
            if (text != null) {
                LookingAtElement.renderScaledText(Minecraft.getInstance(), matrix, currentX + 4, currentY + 3, 0xFFFFFF, 92, text);
                currentY += 15;
            }
            continue;
        } else if (elementData.contains(NBTConstants.ENERGY_STORED, NBT.TAG_STRING)) {
            element = new EnergyElement(FloatingLong.parseFloatingLong(elementData.getString(NBTConstants.ENERGY_STORED), true), FloatingLong.parseFloatingLong(elementData.getString(NBTConstants.MAX), true));
        } else if (elementData.contains(NBTConstants.FLUID_STORED, NBT.TAG_COMPOUND)) {
            element = new FluidElement(FluidStack.loadFluidStackFromNBT(elementData.getCompound(NBTConstants.FLUID_STORED)), elementData.getInt(NBTConstants.MAX));
        } else if (elementData.contains(MekanismHwylaPlugin.CHEMICAL_STACK, NBT.TAG_COMPOUND)) {
            ChemicalStack<?> chemicalStack;
            CompoundNBT chemicalData = elementData.getCompound(MekanismHwylaPlugin.CHEMICAL_STACK);
            if (chemicalData.contains(NBTConstants.GAS_NAME, NBT.TAG_STRING)) {
                chemicalStack = GasStack.readFromNBT(chemicalData);
            } else if (chemicalData.contains(NBTConstants.INFUSE_TYPE_NAME, NBT.TAG_STRING)) {
                chemicalStack = InfusionStack.readFromNBT(chemicalData);
            } else if (chemicalData.contains(NBTConstants.PIGMENT_NAME, NBT.TAG_STRING)) {
                chemicalStack = PigmentStack.readFromNBT(chemicalData);
            } else if (chemicalData.contains(NBTConstants.SLURRY_NAME, NBT.TAG_STRING)) {
                chemicalStack = SlurryStack.readFromNBT(chemicalData);
            } else {
                // Unknown chemical
                continue;
            }
            element = new ChemicalElement(chemicalStack, elementData.getLong(NBTConstants.MAX));
        } else {
            // Skip
            continue;
        }
        element.render(matrix, currentX, currentY);
        currentY += 15;
    }
}
Also used : FluidElement(mekanism.common.integration.lookingat.FluidElement) ListNBT(net.minecraft.nbt.ListNBT) ChemicalElement(mekanism.common.integration.lookingat.ChemicalElement) EnergyElement(mekanism.common.integration.lookingat.EnergyElement) CompoundNBT(net.minecraft.nbt.CompoundNBT) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) LookingAtElement(mekanism.common.integration.lookingat.LookingAtElement) ITextComponent(net.minecraft.util.text.ITextComponent) ChemicalStack(mekanism.api.chemical.ChemicalStack)

Example 4 with ChemicalStack

use of mekanism.api.chemical.ChemicalStack in project Mekanism by mekanism.

the class ChemicalCrystallizerInputRecipeCache method findFirstRecipe.

@Nullable
private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> ChemicalCrystallizerRecipe findFirstRecipe(ChemicalType type, STACK stack) {
    Predicate<ChemicalCrystallizerRecipe> matchPredicate = recipe -> ((IChemicalStackIngredient<CHEMICAL, STACK>) recipe.getInput()).test(stack);
    ChemicalInputCache<CHEMICAL, STACK, ChemicalCrystallizerRecipe> cache = (ChemicalInputCache<CHEMICAL, STACK, ChemicalCrystallizerRecipe>) typeBasedCache.get(type);
    ChemicalCrystallizerRecipe recipe = cache.findFirstRecipe(stack, matchPredicate);
    return recipe == null ? findFirstRecipe(typeBasedComplexRecipes.get(type), matchPredicate) : recipe;
}
Also used : EnumUtils(mekanism.common.util.EnumUtils) MekanismRecipeType(mekanism.common.recipe.MekanismRecipeType) EnumMap(java.util.EnumMap) ChemicalStack(mekanism.api.chemical.ChemicalStack) Predicate(java.util.function.Predicate) World(net.minecraft.world.World) Set(java.util.Set) ChemicalCrystallizerRecipe(mekanism.api.recipes.ChemicalCrystallizerRecipe) ChemicalInputCache(mekanism.common.recipe.lookup.cache.type.ChemicalInputCache) ChemicalType(mekanism.api.chemical.ChemicalType) HashSet(java.util.HashSet) List(java.util.List) Chemical(mekanism.api.chemical.Chemical) Map(java.util.Map) Nullable(javax.annotation.Nullable) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) ChemicalInputCache(mekanism.common.recipe.lookup.cache.type.ChemicalInputCache) ChemicalCrystallizerRecipe(mekanism.api.recipes.ChemicalCrystallizerRecipe) Nullable(javax.annotation.Nullable)

Example 5 with ChemicalStack

use of mekanism.api.chemical.ChemicalStack in project Mekanism by mekanism.

the class ChemicalCrystallizerInputRecipeCache method containsInput.

/**
 * Checks if there is a matching recipe that has the given input.
 *
 * @param world World.
 * @param input Recipe input.
 *
 * @return {@code true} if there is a match, {@code false} if there isn't.
 */
public <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> boolean containsInput(@Nullable World world, CHEMICAL input) {
    if (input.isEmptyType()) {
        // Don't allow empty inputs
        return false;
    }
    initCacheIfNeeded(world);
    ChemicalType type = ChemicalType.getTypeFor(input);
    STACK stack = (STACK) input.getStack(1);
    return containsInput(type, stack) || typeBasedComplexRecipes.get(type).stream().anyMatch(recipe -> recipe.testType(stack));
}
Also used : EnumUtils(mekanism.common.util.EnumUtils) MekanismRecipeType(mekanism.common.recipe.MekanismRecipeType) EnumMap(java.util.EnumMap) ChemicalStack(mekanism.api.chemical.ChemicalStack) Predicate(java.util.function.Predicate) World(net.minecraft.world.World) Set(java.util.Set) ChemicalCrystallizerRecipe(mekanism.api.recipes.ChemicalCrystallizerRecipe) ChemicalInputCache(mekanism.common.recipe.lookup.cache.type.ChemicalInputCache) ChemicalType(mekanism.api.chemical.ChemicalType) HashSet(java.util.HashSet) List(java.util.List) Chemical(mekanism.api.chemical.Chemical) Map(java.util.Map) Nullable(javax.annotation.Nullable) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack) ChemicalType(mekanism.api.chemical.ChemicalType)

Aggregations

ChemicalStack (mekanism.api.chemical.ChemicalStack)6 Map (java.util.Map)5 List (java.util.List)4 Set (java.util.Set)4 Nullable (javax.annotation.Nullable)4 Collections (java.util.Collections)3 EnumMap (java.util.EnumMap)3 HashSet (java.util.HashSet)3 Chemical (mekanism.api.chemical.Chemical)3 IChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient)3 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 Arrays (java.util.Arrays)2 Predicate (java.util.function.Predicate)2 ChemicalType (mekanism.api.chemical.ChemicalType)2 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)2 ChemicalCrystallizerRecipe (mekanism.api.recipes.ChemicalCrystallizerRecipe)2 MekanismRecipeType (mekanism.common.recipe.MekanismRecipeType)2 ChemicalInputCache (mekanism.common.recipe.lookup.cache.type.ChemicalInputCache)2 EnumUtils (mekanism.common.util.EnumUtils)2 Item (net.minecraft.item.Item)2