Search in sources :

Example 1 with GasStack

use of mekanism.api.chemical.gas.GasStack 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 GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class ItemStackGasToItemStackRecipeCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, ItemStackGasToItemStackRecipe recipe, IIngredients ingredients) {
    IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
    initItem(itemStacks, 0, true, input, recipe.getItemInput().getRepresentations());
    initItem(itemStacks, 1, false, output, recipe.getOutputDefinition());
    List<ItemStack> gasItemProviders = new ArrayList<>();
    List<GasStack> scaledGases = new ArrayList<>();
    for (GasStack gas : recipe.getChemicalInput().getRepresentations()) {
        gasItemProviders.addAll(MekanismJEI.GAS_STACK_HELPER.getStacksFor(gas.getType(), true));
        // While we are already looping the gases ensure we scale it to get the average amount that will get used over all
        scaledGases.add(new GasStack(gas, gas.getAmount() * TileEntityAdvancedElectricMachine.BASE_TICKS_REQUIRED));
    }
    initItem(itemStacks, 2, true, extra, gasItemProviders);
    IGuiIngredientGroup<GasStack> gasStacks = recipeLayout.getIngredientsGroup(MekanismJEI.TYPE_GAS);
    initChemical(gasStacks, 0, true, gasInput, scaledGases);
}
Also used : IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) ArrayList(java.util.ArrayList) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack)

Example 3 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class NucleosynthesizingRecipeCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, NucleosynthesizingRecipe recipe, IIngredients ingredients) {
    IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
    initItem(itemStacks, 0, true, input, recipe.getItemInput().getRepresentations());
    initItem(itemStacks, 1, false, output, recipe.getOutputDefinition());
    List<ItemStack> gasItemProviders = new ArrayList<>();
    List<@NonNull GasStack> gasInputs = recipe.getChemicalInput().getRepresentations();
    for (GasStack gas : gasInputs) {
        gasItemProviders.addAll(MekanismJEI.GAS_STACK_HELPER.getStacksFor(gas.getType(), true));
    }
    initItem(itemStacks, 2, true, extra, gasItemProviders);
    initChemical(recipeLayout.getIngredientsGroup(MekanismJEI.TYPE_GAS), 0, true, gasInput, gasInputs);
}
Also used : IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) ArrayList(java.util.ArrayList) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack)

Example 4 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class PressurizedReactionRecipeCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, PressurizedReactionRecipe recipe, IIngredients ingredients) {
    IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
    initItem(itemStacks, 0, true, inputItem, recipe.getInputSolid().getRepresentations());
    Pair<List<@NonNull ItemStack>, @NonNull GasStack> outputDefinition = recipe.getOutputDefinition();
    initItem(itemStacks, 1, false, outputItem, outputDefinition.getLeft());
    initFluid(recipeLayout.getFluidStacks(), 0, true, inputFluid, recipe.getInputFluid().getRepresentations());
    IGuiIngredientGroup<GasStack> gasStacks = recipeLayout.getIngredientsGroup(MekanismJEI.TYPE_GAS);
    initChemical(gasStacks, 0, true, inputGas, recipe.getInputGas().getRepresentations());
    initChemical(gasStacks, 1, false, outputGas, Collections.singletonList(outputDefinition.getRight()));
}
Also used : NonNull(mekanism.api.annotations.NonNull) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) List(java.util.List) GasStack(mekanism.api.chemical.gas.GasStack)

Example 5 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class GasInventorySlot method fillOrConvert.

/**
 * Fills the tank from this item OR converts the given item to a gas
 */
public static GasInventorySlot fillOrConvert(IGasTank gasTank, Supplier<World> worldSupplier, @Nullable IContentsListener listener, int x, int y) {
    Objects.requireNonNull(gasTank, "Gas tank cannot be null");
    Objects.requireNonNull(worldSupplier, "World supplier cannot be null");
    Function<ItemStack, GasStack> potentialConversionSupplier = stack -> getPotentialConversion(worldSupplier.get(), stack);
    return new GasInventorySlot(gasTank, worldSupplier, getFillOrConvertExtractPredicate(gasTank, GasInventorySlot::getCapability, potentialConversionSupplier), getFillOrConvertInsertPredicate(gasTank, GasInventorySlot::getCapability, potentialConversionSupplier), stack -> {
        if (stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).isPresent()) {
            // Note: we mark all gas items as valid and have a more restrictive insert check so that we allow full tanks when they are done being filled
            return true;
        }
        // Allow gas conversion of items that have a gas that is valid
        GasStack gasConversion = getPotentialConversion(worldSupplier.get(), stack);
        return !gasConversion.isEmpty() && gasTank.isValid(gasConversion);
    }, listener, x, y);
}
Also used : Gas(mekanism.api.chemical.gas.Gas) IGasHandler(mekanism.api.chemical.gas.IGasHandler) MethodsReturnNonnullByDefault(mcp.MethodsReturnNonnullByDefault) MekanismRecipeType(mekanism.common.recipe.MekanismRecipeType) Predicate(java.util.function.Predicate) IMekanismInventory(mekanism.api.inventory.IMekanismInventory) World(net.minecraft.world.World) IChemicalHandler(mekanism.api.chemical.IChemicalHandler) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) BooleanSupplier(java.util.function.BooleanSupplier) Objects(java.util.Objects) IContentsListener(mekanism.api.IContentsListener) ItemStack(net.minecraft.item.ItemStack) FieldsAreNonnullByDefault(mekanism.api.annotations.FieldsAreNonnullByDefault) IGasTank(mekanism.api.chemical.gas.IGasTank) Capabilities(mekanism.common.capabilities.Capabilities) GasStack(mekanism.api.chemical.gas.GasStack) NonNull(mekanism.api.annotations.NonNull) Nullable(javax.annotation.Nullable) ItemStackToGasRecipe(mekanism.api.recipes.ItemStackToGasRecipe) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

GasStack (mekanism.api.chemical.gas.GasStack)44 ItemStack (net.minecraft.item.ItemStack)17 JsonSyntaxException (com.google.gson.JsonSyntaxException)8 IngredientHelper (mekanism.common.integration.projecte.IngredientHelper)8 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)7 FluidStack (net.minecraftforge.fluids.FluidStack)7 List (java.util.List)6 IGasHandler (mekanism.api.chemical.gas.IGasHandler)6 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)6 FloatingLong (mekanism.api.math.FloatingLong)6 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)6 NonNull (mekanism.api.annotations.NonNull)5 InfusionStack (mekanism.api.chemical.infuse.InfusionStack)5 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)5 Nonnull (javax.annotation.Nonnull)4 JsonElement (com.google.gson.JsonElement)3 Collections (java.util.Collections)3 Nullable (javax.annotation.Nullable)3 ChemicalType (mekanism.api.chemical.ChemicalType)3 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)3