Search in sources :

Example 1 with TileSpectralRelay

use of hellfirepvp.astralsorcery.common.tile.TileSpectralRelay 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 2 with TileSpectralRelay

use of hellfirepvp.astralsorcery.common.tile.TileSpectralRelay 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 3 with TileSpectralRelay

use of hellfirepvp.astralsorcery.common.tile.TileSpectralRelay 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 4 with TileSpectralRelay

use of hellfirepvp.astralsorcery.common.tile.TileSpectralRelay in project AstralSorcery by HellFirePvP.

the class TileAltar method nearbyRelays.

@Nonnull
public Set<BlockPos> nearbyRelays() {
    Set<BlockPos> eligableRelayOffsets = new HashSet<>();
    for (int xx = -3; xx <= 3; xx++) {
        for (int zz = -3; zz <= 3; zz++) {
            if (xx == 0 && zz == 0) {
                // Not that it matters though
                continue;
            }
            BlockPos offset = new BlockPos(xx, 0, zz);
            TileSpectralRelay tar = MiscUtils.getTileAt(getWorld(), getPos().add(offset), TileSpectralRelay.class, true);
            if (tar != null) {
                eligableRelayOffsets.add(getPos().add(offset));
            }
        }
    }
    return eligableRelayOffsets;
}
Also used : TileSpectralRelay(hellfirepvp.astralsorcery.common.tile.TileSpectralRelay) BlockPos(net.minecraft.util.math.BlockPos) Nonnull(javax.annotation.Nonnull)

Example 5 with TileSpectralRelay

use of hellfirepvp.astralsorcery.common.tile.TileSpectralRelay 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

TileSpectralRelay (hellfirepvp.astralsorcery.common.tile.TileSpectralRelay)6 ItemStack (net.minecraft.item.ItemStack)5 CraftingFocusStack (hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack)4 WrappedIngredient (hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient)4 TileInventory (hellfirepvp.astralsorcery.common.util.tile.TileInventory)3 BlockPos (net.minecraft.util.math.BlockPos)3 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)3 FluidIngredient (hellfirepvp.astralsorcery.common.crafting.helper.ingredient.FluidIngredient)2 ActiveSimpleAltarRecipe (hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe)2 Nonnull (javax.annotation.Nonnull)2 Ingredient (net.minecraft.item.crafting.Ingredient)2 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)2 AstralSorcery (hellfirepvp.astralsorcery.AstralSorcery)1 SimpleAltarRecipe (hellfirepvp.astralsorcery.common.crafting.recipe.SimpleAltarRecipe)1 ResearchManager (hellfirepvp.astralsorcery.common.data.research.ResearchManager)1 TileAltar (hellfirepvp.astralsorcery.common.tile.altar.TileAltar)1 MiscUtils (hellfirepvp.astralsorcery.common.util.MiscUtils)1 RecipeHelper (hellfirepvp.astralsorcery.common.util.RecipeHelper)1 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)1 ItemUtils (hellfirepvp.astralsorcery.common.util.item.ItemUtils)1