Search in sources :

Example 1 with CraftingFocusStack

use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.

the class ActiveSimpleAltarRecipe method serialize.

@Nonnull
public CompoundNBT serialize() {
    CompoundNBT compound = new CompoundNBT();
    compound.putString("recipeToCraft", getRecipeToCraft().getId().toString());
    compound.putUniqueId("playerCraftingUUID", getPlayerCraftingUUID());
    compound.putInt("ticksCrafting", getTicksCrafting());
    compound.putInt("totalCraftingTime", getTotalCraftingTime());
    compound.putInt("state", getState().ordinal());
    compound.put("craftingData", craftingData);
    ListNBT list = new ListNBT();
    for (CraftingFocusStack stack : this.focusStacks) {
        list.add(stack.serialize());
    }
    compound.put("focusStacks", list);
    return compound;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) CraftingFocusStack(hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack) Nonnull(javax.annotation.Nonnull)

Example 2 with CraftingFocusStack

use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.

the class ActiveSimpleAltarRecipe method consumeInputs.

public void consumeInputs(TileAltar altar) {
    TileInventory inv = altar.getInventory();
    AltarRecipeGrid grid = this.recipeToCraft.getInputs();
    for (int slot = 0; slot < AltarRecipeGrid.MAX_INVENTORY_SIZE; slot++) {
        Ingredient input = grid.getIngredient(slot);
        if (input instanceof FluidIngredient) {
            ItemStack stack = inv.getStackInSlot(slot);
            FluidActionResult far = FluidUtil.tryEmptyContainer(stack, VoidFluidHandler.INSTANCE, FluidAttributes.BUCKET_VOLUME, null, true);
            if (far.isSuccess()) {
                inv.setStackInSlot(slot, far.getResult());
            }
        } else {
            ItemUtils.decrementItem(inv, slot, altar::dropItemOnTop);
        }
    }
    for (CraftingFocusStack input : this.focusStacks) {
        TileSpectralRelay tar = MiscUtils.getTileAt(altar.getWorld(), input.getRealPosition(), TileSpectralRelay.class, true);
        if (tar != null) {
            TileInventory tarInventory = tar.getInventory();
            if (input.getInput() != null && input.getInput().getIngredient() instanceof FluidIngredient) {
                ItemStack stack = tarInventory.getStackInSlot(0);
                FluidActionResult far = FluidUtil.tryEmptyContainer(stack, VoidFluidHandler.INSTANCE, FluidAttributes.BUCKET_VOLUME, null, true);
                if (far.isSuccess()) {
                    tarInventory.setStackInSlot(0, far.getResult());
                }
            } else {
                ItemUtils.decrementItem(tarInventory, 0, altar::dropItemOnTop);
            }
        }
    }
}
Also used : FluidIngredient(hellfirepvp.astralsorcery.common.crafting.helper.ingredient.FluidIngredient) Ingredient(net.minecraft.item.crafting.Ingredient) WrappedIngredient(hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient) FluidIngredient(hellfirepvp.astralsorcery.common.crafting.helper.ingredient.FluidIngredient) TileSpectralRelay(hellfirepvp.astralsorcery.common.tile.TileSpectralRelay) TileInventory(hellfirepvp.astralsorcery.common.util.tile.TileInventory) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) CraftingFocusStack(hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack)

Example 3 with CraftingFocusStack

use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.

the class BuiltInEffectTraitRelayHighlight method onTESR.

@Override
@OnlyIn(Dist.CLIENT)
public void onTESR(TileAltar altar, ActiveSimpleAltarRecipe.CraftingState state, MatrixStack renderStack, IRenderTypeBuffer buffer, float pTicks, int combinedLight) {
    ActiveSimpleAltarRecipe activeRecipe = altar.getActiveRecipe();
    if (activeRecipe != null) {
        List<WrappedIngredient> additionalIngredients = activeRecipe.getRecipeToCraft().getRelayInputs();
        List<CraftingFocusStack> focusStacks = activeRecipe.getFocusStacks();
        for (CraftingFocusStack stack : focusStacks) {
            if (stack.getStackIndex() < 0 || stack.getStackIndex() >= additionalIngredients.size()) {
                continue;
            }
            WrappedIngredient match = additionalIngredients.get(stack.getStackIndex());
            BlockPos offset = stack.getRealPosition().subtract(altar.getPos());
            TileSpectralRelay relay = MiscUtils.getTileAt(altar.getWorld(), stack.getRealPosition(), TileSpectralRelay.class, false);
            if (relay == null || (!match.getIngredient().test(relay.getInventory().getStackInSlot(0)))) {
                ItemStack potential = match.getRandomMatchingStack(getClientTick());
                renderStack.push();
                renderStack.translate(0.5 + offset.getX(), 0.35 + offset.getY(), 0.5 + offset.getZ());
                RenderingUtils.renderTranslucentItemStack(potential, renderStack, pTicks);
                renderStack.pop();
            }
        }
    }
}
Also used : ActiveSimpleAltarRecipe(hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe) TileSpectralRelay(hellfirepvp.astralsorcery.common.tile.TileSpectralRelay) BlockPos(net.minecraft.util.math.BlockPos) WrappedIngredient(hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient) CraftingFocusStack(hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack) ItemStack(net.minecraft.item.ItemStack) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 4 with CraftingFocusStack

use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.

the class BuiltInEffectTraitRelayHighlight method onTick.

@Override
@OnlyIn(Dist.CLIENT)
public void onTick(TileAltar altar, ActiveSimpleAltarRecipe.CraftingState state) {
    ActiveSimpleAltarRecipe recipe = altar.getActiveRecipe();
    if (recipe != null) {
        List<WrappedIngredient> additionalIngredients = recipe.getRecipeToCraft().getRelayInputs();
        for (CraftingFocusStack stack : recipe.getFocusStacks()) {
            if (stack.getStackIndex() < 0 || stack.getStackIndex() >= additionalIngredients.size()) {
                continue;
            }
            WrappedIngredient match = additionalIngredients.get(stack.getStackIndex());
            TileSpectralRelay relay = MiscUtils.getTileAt(altar.getWorld(), stack.getRealPosition(), TileSpectralRelay.class, false);
            if (relay != null) {
                ItemStack in = relay.getInventory().getStackInSlot(0);
                if (!in.isEmpty() && match.getIngredient().test(in)) {
                    Color color = ColorizationHelper.getColor(in).orElse(ColorsAS.CELESTIAL_CRYSTAL);
                    playLightbeam(altar, relay, color);
                    playRelayHighlightParticles(relay, color);
                    if (rand.nextInt(4) == 0) {
                        EffectHelper.of(EffectTemplatesAS.GENERIC_PARTICLE).spawn(new Vector3(altar).add(-3 + rand.nextInt(7), 0.02, -3 + rand.nextInt(7))).color(VFXColorFunction.constant(color)).alpha(VFXAlphaFunction.FADE_OUT).setScaleMultiplier(0.15F + rand.nextFloat() * 0.2F);
                    }
                } else {
                    ItemStack chosen = match.getRandomMatchingStack(getClientTick());
                    Color color = ColorizationHelper.getColor(chosen).orElse(ColorsAS.CELESTIAL_CRYSTAL);
                    playLightbeam(altar, relay, color);
                    playRelayHighlightParticles(relay, color);
                }
            }
        }
    }
}
Also used : ActiveSimpleAltarRecipe(hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe) TileSpectralRelay(hellfirepvp.astralsorcery.common.tile.TileSpectralRelay) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) WrappedIngredient(hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient) CraftingFocusStack(hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack) ItemStack(net.minecraft.item.ItemStack) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 5 with CraftingFocusStack

use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.

the class ActiveSimpleAltarRecipe method deserialize.

@Nullable
public static ActiveSimpleAltarRecipe deserialize(CompoundNBT compound, @Nullable ActiveSimpleAltarRecipe previous) {
    RecipeManager mgr = RecipeHelper.getRecipeManager();
    if (mgr == null) {
        return null;
    }
    ResourceLocation recipeKey = new ResourceLocation(compound.getString("recipeToCraft"));
    Optional<?> recipe = mgr.getRecipe(recipeKey);
    if (!recipe.isPresent() || !(recipe.get() instanceof SimpleAltarRecipe)) {
        AstralSorcery.log.info("Recipe with unknown/invalid name found: " + recipeKey);
        return null;
    }
    SimpleAltarRecipe altarRecipe = (SimpleAltarRecipe) recipe.get();
    UUID uuidCraft = compound.getUniqueId("playerCraftingUUID");
    int tick = compound.getInt("ticksCrafting");
    int total = compound.getInt("totalCraftingTime");
    CraftingState state = CraftingState.values()[compound.getInt("state")];
    List<CraftingFocusStack> stacks = new LinkedList<>();
    ListNBT listStacks = compound.getList("focusStacks", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < listStacks.size(); i++) {
        stacks.add(new CraftingFocusStack(listStacks.getCompound(i)));
    }
    ActiveSimpleAltarRecipe task = new ActiveSimpleAltarRecipe(altarRecipe, uuidCraft);
    task.ticksCrafting = tick;
    task.totalCraftingTime = total;
    task.setState(state);
    task.craftingData = compound.getCompound("craftingData");
    task.focusStacks = stacks;
    task.recoverContainedEffects(previous);
    return task;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) ResourceLocation(net.minecraft.util.ResourceLocation) RecipeManager(net.minecraft.item.crafting.RecipeManager) CraftingFocusStack(hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack) SimpleAltarRecipe(hellfirepvp.astralsorcery.common.crafting.recipe.SimpleAltarRecipe) Nullable(javax.annotation.Nullable)

Aggregations

CraftingFocusStack (hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack)6 WrappedIngredient (hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient)4 TileSpectralRelay (hellfirepvp.astralsorcery.common.tile.TileSpectralRelay)4 ItemStack (net.minecraft.item.ItemStack)4 ListNBT (net.minecraft.nbt.ListNBT)3 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)3 FluidIngredient (hellfirepvp.astralsorcery.common.crafting.helper.ingredient.FluidIngredient)2 SimpleAltarRecipe (hellfirepvp.astralsorcery.common.crafting.recipe.SimpleAltarRecipe)2 ActiveSimpleAltarRecipe (hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe)2 TileInventory (hellfirepvp.astralsorcery.common.util.tile.TileInventory)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 Ingredient (net.minecraft.item.crafting.Ingredient)2 RecipeManager (net.minecraft.item.crafting.RecipeManager)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlockPos (net.minecraft.util.math.BlockPos)2 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)2 AstralSorcery (hellfirepvp.astralsorcery.AstralSorcery)1 ResearchManager (hellfirepvp.astralsorcery.common.data.research.ResearchManager)1