Search in sources :

Example 1 with WrappedIngredient

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

the class RenderAltar method render.

@Override
public void render(TileAltar tile, float pTicks, MatrixStack renderStack, IRenderTypeBuffer renderTypeBuffer, int combinedLight, int combinedOverlay) {
    if (tile.getAltarType().isThisGEThan(AltarType.RADIANCE) && tile.hasMultiblock()) {
        IConstellation cst = tile.getFocusedConstellation();
        if (cst != null) {
            float dayAlpha = DayTimeHelper.getCurrentDaytimeDistribution(tile.getWorld()) * 0.6F;
            int max = 3000;
            int t = (int) (ClientScheduler.getClientTick() % max);
            float halfAge = max / 2F;
            float tr = 1F - (Math.abs(halfAge - t) / halfAge);
            tr *= 1.3;
            RenderingConstellationUtils.renderConstellationIntoWorldFlat(cst, renderStack, renderTypeBuffer, new Vector3(0.5, 0.03, 0.5), 5.5 + tr, 2, 0.1F + dayAlpha);
        }
    }
    ActiveSimpleAltarRecipe recipe = tile.getActiveRecipe();
    if (recipe != null) {
        recipe.getRecipeToCraft().getCraftingEffects().forEach(effect -> effect.onTESR(tile, recipe.getState(), renderStack, renderTypeBuffer, pTicks, combinedLight));
    }
    if (tile.getAltarType().isThisGEThan(AltarType.RADIANCE) && tile.hasMultiblock()) {
        renderStack.push();
        renderStack.translate(0.5F, 4.5F, 0.5F);
        long id = tile.getPos().toLong();
        if (recipe != null) {
            List<WrappedIngredient> traitInputs = recipe.getRecipeToCraft().getRelayInputs();
            if (!traitInputs.isEmpty()) {
                int amount = 60 / traitInputs.size();
                for (int i = 0; i < traitInputs.size(); i++) {
                    WrappedIngredient ingredient = traitInputs.get(i);
                    ItemStack traitInput = ingredient.getRandomMatchingStack(ClientScheduler.getClientTick());
                    Color color = ColorizationHelper.getColor(traitInput).orElse(ColorsAS.CELESTIAL_CRYSTAL);
                    RenderingDrawUtils.renderLightRayFan(renderStack, renderTypeBuffer, color, 0x1231943167156902L | id | (i * 0x5151L), 20, 2F, amount);
                }
            } else {
                RenderingDrawUtils.renderLightRayFan(renderStack, renderTypeBuffer, Color.WHITE, id * 31L, 15, 1.5F, 35);
                RenderingDrawUtils.renderLightRayFan(renderStack, renderTypeBuffer, ColorsAS.CELESTIAL_CRYSTAL, id * 16L, 10, 1F, 25);
            }
            RenderingDrawUtils.renderLightRayFan(renderStack, renderTypeBuffer, Color.WHITE, id * 31L, 10, 1F, 10);
        } else {
            RenderingDrawUtils.renderLightRayFan(renderStack, renderTypeBuffer, Color.WHITE, id * 31L, 15, 1.5F, 35);
            RenderingDrawUtils.renderLightRayFan(renderStack, renderTypeBuffer, ColorsAS.CELESTIAL_CRYSTAL, id * 16L, 10, 1F, 25);
        }
        renderStack.pop();
    }
}
Also used : ActiveSimpleAltarRecipe(hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) WrappedIngredient(hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient) ItemStack(net.minecraft.item.ItemStack) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation)

Example 2 with WrappedIngredient

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

the class SimpleAltarRecipe method write.

public final void write(JsonObject object) {
    object.addProperty("altar_type", this.getAltarType().ordinal());
    object.addProperty("duration", this.getDuration());
    object.addProperty("starlight", this.getStarlightRequirement());
    this.getInputs().serialize(object);
    if (this.getCustomRecipeType() != null) {
        object.addProperty("recipe_class", this.getCustomRecipeType().toString());
    }
    JsonArray outputs = new JsonArray();
    for (ItemStack output : this.outputs) {
        outputs.add(JsonHelper.serializeItemStack(output));
    }
    object.add("output", outputs);
    JsonObject options = new JsonObject();
    this.serializeAdditionalJson(options);
    if (!options.entrySet().isEmpty()) {
        object.add("options", options);
    }
    if (this.getFocusConstellation() != null) {
        object.addProperty("focus_constellation", this.getFocusConstellation().getRegistryName().toString());
    }
    if (!this.getRelayInputs().isEmpty()) {
        JsonArray inputs = new JsonArray();
        for (WrappedIngredient traitInput : this.getRelayInputs()) {
            inputs.add(traitInput.getIngredient().serialize());
        }
        object.add("relay_inputs", inputs);
    }
    if (!this.getCraftingEffects().isEmpty()) {
        JsonArray effects = new JsonArray();
        for (AltarRecipeEffect effect : this.getCraftingEffects()) {
            effects.add(effect.getRegistryName().toString());
        }
        object.add("effects", effects);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) WrappedIngredient(hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient) ItemStack(net.minecraft.item.ItemStack) AltarRecipeEffect(hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect)

Example 3 with WrappedIngredient

use of hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient 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 WrappedIngredient

use of hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient 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 WrappedIngredient

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

the class ActiveSimpleAltarRecipe method tickCraftingRelayInputs.

private boolean tickCraftingRelayInputs(TileAltar altar, List<WrappedIngredient> iIngredients) {
    // Start the surrounding stack intake past 66%
    int part = totalCraftingTime / 3;
    // Every input is evenly spread
    int cttPart = part / (iIngredients.size()) + 1;
    boolean waitMissingInputs = false;
    for (int i = 0; i < iIngredients.size(); i++) {
        WrappedIngredient input = iIngredients.get(i);
        int index = i;
        int offset = part + (index * cttPart);
        if (this.ticksCrafting >= offset) {
            CraftingFocusStack found = MiscUtils.iterativeSearch(this.focusStacks, fStack -> fStack.getStackIndex() == index);
            if (found == null) {
                Set<BlockPos> relays = altar.nearbyRelays();
                relays.removeIf(pos -> MiscUtils.contains(this.focusStacks, fs -> fs.getRealPosition().equals(pos)));
                // No unused relay found for a new focus-stack..
                if (relays.isEmpty()) {
                    waitMissingInputs = true;
                    continue;
                }
                BlockPos at = MiscUtils.getRandomEntry(relays, rand);
                TileSpectralRelay tar = MiscUtils.getTileAt(altar.getWorld(), at, TileSpectralRelay.class, true);
                if (tar == null) {
                    // We were lied to. lol.
                    waitMissingInputs = true;
                    continue;
                }
                found = new CraftingFocusStack(index, input, at);
                this.focusStacks.add(found);
            }
            TileSpectralRelay tar = MiscUtils.getTileAt(altar.getWorld(), found.getRealPosition(), TileSpectralRelay.class, true);
            if (tar == null) {
                waitMissingInputs = true;
                continue;
            }
            if (!input.getIngredient().test(tar.getInventory().getStackInSlot(0))) {
                waitMissingInputs = true;
            }
        }
    }
    return waitMissingInputs;
}
Also used : ResearchManager(hellfirepvp.astralsorcery.common.data.research.ResearchManager) Ingredient(net.minecraft.item.crafting.Ingredient) FluidUtil(net.minecraftforge.fluids.FluidUtil) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) VoidFluidHandler(net.minecraftforge.fluids.capability.templates.VoidFluidHandler) Constants(net.minecraftforge.common.util.Constants) WrappedIngredient(hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient) CompoundNBT(net.minecraft.nbt.CompoundNBT) TileAltar(hellfirepvp.astralsorcery.common.tile.altar.TileAltar) Function(java.util.function.Function) Dist(net.minecraftforge.api.distmarker.Dist) FluidAttributes(net.minecraftforge.fluids.FluidAttributes) SimpleAltarRecipe(hellfirepvp.astralsorcery.common.crafting.recipe.SimpleAltarRecipe) ItemStack(net.minecraft.item.ItemStack) MinecraftServer(net.minecraft.server.MinecraftServer) RecipeManager(net.minecraft.item.crafting.RecipeManager) AstralSorcery(hellfirepvp.astralsorcery.AstralSorcery) TileInventory(hellfirepvp.astralsorcery.common.util.tile.TileInventory) MiscUtils(hellfirepvp.astralsorcery.common.util.MiscUtils) TileSpectralRelay(hellfirepvp.astralsorcery.common.tile.TileSpectralRelay) Nonnull(javax.annotation.Nonnull) LogicalSidedProvider(net.minecraftforge.fml.LogicalSidedProvider) Nullable(javax.annotation.Nullable) LogicalSide(net.minecraftforge.fml.LogicalSide) ListNBT(net.minecraft.nbt.ListNBT) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) FluidIngredient(hellfirepvp.astralsorcery.common.crafting.helper.ingredient.FluidIngredient) RecipeHelper(hellfirepvp.astralsorcery.common.util.RecipeHelper) Consumer(java.util.function.Consumer) CraftingFocusStack(hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack) ResourceLocation(net.minecraft.util.ResourceLocation) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) ItemUtils(hellfirepvp.astralsorcery.common.util.item.ItemUtils) 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)

Aggregations

WrappedIngredient (hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient)6 ItemStack (net.minecraft.item.ItemStack)5 CraftingFocusStack (hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack)3 ActiveSimpleAltarRecipe (hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe)3 TileSpectralRelay (hellfirepvp.astralsorcery.common.tile.TileSpectralRelay)3 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)3 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)2 BlockPos (net.minecraft.util.math.BlockPos)2 ImmutableList (com.google.common.collect.ImmutableList)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 AstralSorcery (hellfirepvp.astralsorcery.AstralSorcery)1 IConstellation (hellfirepvp.astralsorcery.common.constellation.IConstellation)1 FluidIngredient (hellfirepvp.astralsorcery.common.crafting.helper.ingredient.FluidIngredient)1 SimpleAltarRecipe (hellfirepvp.astralsorcery.common.crafting.recipe.SimpleAltarRecipe)1 AltarRecipeGrid (hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid)1 AltarRecipeEffect (hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect)1 ResearchManager (hellfirepvp.astralsorcery.common.data.research.ResearchManager)1 TileAltar (hellfirepvp.astralsorcery.common.tile.altar.TileAltar)1 MiscUtils (hellfirepvp.astralsorcery.common.util.MiscUtils)1