Search in sources :

Example 1 with InfusionStack

use of mekanism.api.chemical.infuse.InfusionStack 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 InfusionStack

use of mekanism.api.chemical.infuse.InfusionStack in project Mekanism by mekanism.

the class MetallurgicInfuserRecipeCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, MetallurgicInfuserRecipe recipe, IIngredients ingredients) {
    IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
    initItem(itemStacks, 0, true, input, recipe.getItemInput().getRepresentations());
    initItem(itemStacks, 1, false, output, recipe.getOutputDefinition());
    List<ItemStack> infuseItemProviders = new ArrayList<>();
    List<@NonNull InfusionStack> infusionStacks = recipe.getChemicalInput().getRepresentations();
    for (InfusionStack infusionStack : infusionStacks) {
        infuseItemProviders.addAll(MekanismJEI.INFUSION_STACK_HELPER.getStacksFor(infusionStack.getType(), true));
    }
    initItem(itemStacks, 2, true, extra, infuseItemProviders);
    initChemical(recipeLayout.getIngredientsGroup(MekanismJEI.TYPE_INFUSION), 0, true, infusionBar, infusionStacks);
}
Also used : InfusionStack(mekanism.api.chemical.infuse.InfusionStack) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 3 with InfusionStack

use of mekanism.api.chemical.infuse.InfusionStack in project Mekanism by mekanism.

the class MetallurgicInfuserRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof MetallurgicInfuserRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    MetallurgicInfuserRecipe recipe = (MetallurgicInfuserRecipe) iRecipe;
    List<@NonNull InfusionStack> infuseTypeRepresentations = recipe.getChemicalInput().getRepresentations();
    List<@NonNull ItemStack> itemRepresentations = recipe.getItemInput().getRepresentations();
    for (InfusionStack infuseTypeRepresentation : infuseTypeRepresentations) {
        NormalizedSimpleStack nssInfuseType = NSSInfuseType.createInfuseType(infuseTypeRepresentation);
        for (ItemStack itemRepresentation : itemRepresentations) {
            ItemStack output = recipe.getOutput(itemRepresentation, infuseTypeRepresentation);
            if (!output.isEmpty()) {
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(nssInfuseType, infuseTypeRepresentation.getAmount());
                ingredientHelper.put(itemRepresentation);
                if (ingredientHelper.addAsConversion(output)) {
                    handled = true;
                }
            }
        }
    }
    return handled;
}
Also used : MetallurgicInfuserRecipe(mekanism.api.recipes.MetallurgicInfuserRecipe) NormalizedSimpleStack(moze_intel.projecte.api.nss.NormalizedSimpleStack) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) ItemStack(net.minecraft.item.ItemStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Example 4 with InfusionStack

use of mekanism.api.chemical.infuse.InfusionStack in project Mekanism by mekanism.

the class ChemicalUtil method getRGBDurabilityForDisplay.

public static int getRGBDurabilityForDisplay(ItemStack stack) {
    GasStack gasStack = StorageUtils.getStoredGasFromNBT(stack);
    if (!gasStack.isEmpty()) {
        return gasStack.getChemicalColorRepresentation();
    }
    InfusionStack infusionStack = StorageUtils.getStoredInfusionFromNBT(stack);
    if (!infusionStack.isEmpty()) {
        return infusionStack.getChemicalColorRepresentation();
    }
    PigmentStack pigmentStack = StorageUtils.getStoredPigmentFromNBT(stack);
    if (!pigmentStack.isEmpty()) {
        return pigmentStack.getChemicalColorRepresentation();
    }
    SlurryStack slurryStack = StorageUtils.getStoredSlurryFromNBT(stack);
    if (!slurryStack.isEmpty()) {
        return slurryStack.getChemicalColorRepresentation();
    }
    return 0;
}
Also used : PigmentStack(mekanism.api.chemical.pigment.PigmentStack) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) GasStack(mekanism.api.chemical.gas.GasStack) SlurryStack(mekanism.api.chemical.slurry.SlurryStack)

Example 5 with InfusionStack

use of mekanism.api.chemical.infuse.InfusionStack in project Mekanism by mekanism.

the class StorageUtils method addStoredSubstance.

/**
 * @implNote Assumes there is only one "tank"
 */
public static void addStoredSubstance(@Nonnull ItemStack stack, @Nonnull List<ITextComponent> tooltip, boolean isCreative) {
    // Note we ensure the capabilities are not null, as the first call to addInformation happens before capability injection
    if (Capabilities.GAS_HANDLER_CAPABILITY == null || Capabilities.INFUSION_HANDLER_CAPABILITY == null || Capabilities.PIGMENT_HANDLER_CAPABILITY == null || Capabilities.SLURRY_HANDLER_CAPABILITY == null || CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY == null) {
        return;
    }
    FluidStack fluidStack = StorageUtils.getStoredFluidFromNBT(stack);
    GasStack gasStack = StorageUtils.getStoredGasFromNBT(stack);
    InfusionStack infusionStack = StorageUtils.getStoredInfusionFromNBT(stack);
    PigmentStack pigmentStack = StorageUtils.getStoredPigmentFromNBT(stack);
    SlurryStack slurryStack = StorageUtils.getStoredSlurryFromNBT(stack);
    if (fluidStack.isEmpty() && gasStack.isEmpty() && infusionStack.isEmpty() && pigmentStack.isEmpty() && slurryStack.isEmpty()) {
        tooltip.add(MekanismLang.EMPTY.translate());
        return;
    }
    ILangEntry type;
    Object contents;
    long amount;
    if (!fluidStack.isEmpty()) {
        contents = fluidStack;
        amount = fluidStack.getAmount();
        type = MekanismLang.LIQUID;
    } else {
        ChemicalStack<?> chemicalStack;
        if (!gasStack.isEmpty()) {
            chemicalStack = gasStack;
            type = MekanismLang.GAS;
        } else if (!infusionStack.isEmpty()) {
            chemicalStack = infusionStack;
            type = MekanismLang.INFUSE_TYPE;
        } else if (!pigmentStack.isEmpty()) {
            chemicalStack = pigmentStack;
            type = MekanismLang.PIGMENT;
        } else if (!slurryStack.isEmpty()) {
            chemicalStack = slurryStack;
            type = MekanismLang.SLURRY;
        } else {
            throw new IllegalStateException("Unknown chemical");
        }
        contents = chemicalStack;
        amount = chemicalStack.getAmount();
    }
    if (isCreative) {
        tooltip.add(type.translateColored(EnumColor.YELLOW, EnumColor.ORANGE, MekanismLang.GENERIC_STORED.translate(contents, EnumColor.GRAY, MekanismLang.INFINITE)));
    } else {
        tooltip.add(type.translateColored(EnumColor.YELLOW, EnumColor.ORANGE, MekanismLang.GENERIC_STORED_MB.translate(contents, EnumColor.GRAY, TextUtils.format(amount))));
    }
}
Also used : PigmentStack(mekanism.api.chemical.pigment.PigmentStack) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) ILangEntry(mekanism.api.text.ILangEntry)

Aggregations

InfusionStack (mekanism.api.chemical.infuse.InfusionStack)10 ItemStack (net.minecraft.item.ItemStack)6 GasStack (mekanism.api.chemical.gas.GasStack)5 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)5 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)5 Collections (java.util.Collections)3 List (java.util.List)3 NonNull (mekanism.api.annotations.NonNull)3 ChemicalStack (mekanism.api.chemical.ChemicalStack)3 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 ChemicalType (mekanism.api.chemical.ChemicalType)2 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)2 ChemicalDissolutionRecipe (mekanism.api.recipes.ChemicalDissolutionRecipe)2 ItemStackToInfuseTypeRecipe (mekanism.api.recipes.ItemStackToInfuseTypeRecipe)2 GuiHorizontalPowerBar (mekanism.client.gui.element.bar.GuiHorizontalPowerBar)2 GaugeType (mekanism.client.gui.element.gauge.GaugeType)2 GuiGasGauge (mekanism.client.gui.element.gauge.GuiGasGauge)2 GuiGauge (mekanism.client.gui.element.gauge.GuiGauge)2 ProgressType (mekanism.client.gui.element.progress.ProgressType)2