Search in sources :

Example 1 with BlockFountain

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

the class TileChalice method tickChaliceInteractions.

private void tickChaliceInteractions() {
    if (getWorld().isBlockPowered(pos) || getWorld().getBlockState(getPos().down()).getBlock() instanceof BlockFountain) {
        return;
    }
    FluidStack thisFluid = this.getTank().getFluid();
    if (thisFluid.isEmpty()) {
        return;
    }
    List<BlockPos> chalicePositions = ChaliceHelper.findNearbyChalices(getWorld(), getPos(), 16);
    Collections.shuffle(chalicePositions, rand);
    for (BlockPos otherChalicePos : chalicePositions) {
        TileChalice otherChalice = MiscUtils.getTileAt(getWorld(), otherChalicePos, TileChalice.class, false);
        if (otherChalice == null) {
            continue;
        }
        FluidStack otherFluid = otherChalice.getTank().getFluid();
        if (otherFluid.isEmpty()) {
            continue;
        }
        LiquidInteractionContext ctx = new LiquidInteractionContext(thisFluid, otherFluid);
        List<LiquidInteraction> recipes = RecipeTypesAS.TYPE_LIQUID_INTERACTION.findMatchingRecipes(ctx);
        LiquidInteraction recipe = LiquidInteraction.pickRecipe(recipes);
        while (recipe != null) {
            if (recipe.consumeInputs(this, otherChalice)) {
                Vector3 thisChaliceV = new Vector3(this).add(0.5, 1.5, 0.5);
                Vector3 otherChaliceV = new Vector3(otherChalicePos).add(0.5, 1.5, 0.5);
                Vector3 target = thisChaliceV.getMidpoint(otherChaliceV);
                recipe.getResult().doResult(getWorld(), target.clone());
                PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.LIQUID_INTERACTION_LINE).addData(buf -> {
                    ByteBufUtils.writeVector(buf, thisChaliceV);
                    ByteBufUtils.writeVector(buf, target);
                    ByteBufUtils.writeFluidStack(buf, thisFluid);
                    ByteBufUtils.writeVector(buf, otherChaliceV);
                    ByteBufUtils.writeVector(buf, target);
                    ByteBufUtils.writeFluidStack(buf, otherFluid);
                });
                PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(getWorld(), target.toBlockPos(), 32));
                return;
            }
            recipes.remove(recipe);
            recipe = LiquidInteraction.pickRecipe(recipes);
        }
    }
}
Also used : BlockFountain(hellfirepvp.astralsorcery.common.block.tile.BlockFountain) FluidStack(net.minecraftforge.fluids.FluidStack) LiquidInteraction(hellfirepvp.astralsorcery.common.crafting.recipe.LiquidInteraction) BlockPos(net.minecraft.util.math.BlockPos) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect) LiquidInteractionContext(hellfirepvp.astralsorcery.common.crafting.recipe.LiquidInteractionContext)

Example 2 with BlockFountain

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

the class ChaliceHelper method findNearbyChalices.

@Nonnull
public static List<BlockPos> findNearbyChalices(World world, BlockPos origin, int distance) {
    Vector3 thisVector = new Vector3(origin).add(0.5, 1.5, 0.5);
    List<BlockPos> foundChalices = BlockDiscoverer.searchForBlocksAround(world, origin, MathHelper.clamp(distance, 0, 16), (w, pos, state) -> !pos.equals(origin) && state.getBlock() instanceof BlockChalice && !w.isBlockPowered(pos) && !(w.getBlockState(pos.down()).getBlock() instanceof BlockFountain));
    foundChalices.removeIf(pos -> {
        Vector3 chaliceVector = new Vector3(pos).add(0.5, 1.5, 0.5);
        RaytraceAssist assist = new RaytraceAssist(thisVector, chaliceVector);
        return !assist.isClear(world);
    });
    return foundChalices;
}
Also used : BlockFountain(hellfirepvp.astralsorcery.common.block.tile.BlockFountain) BlockChalice(hellfirepvp.astralsorcery.common.block.tile.BlockChalice) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) BlockPos(net.minecraft.util.math.BlockPos) RaytraceAssist(hellfirepvp.astralsorcery.common.util.RaytraceAssist) Nonnull(javax.annotation.Nonnull)

Aggregations

BlockFountain (hellfirepvp.astralsorcery.common.block.tile.BlockFountain)2 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)2 BlockPos (net.minecraft.util.math.BlockPos)2 BlockChalice (hellfirepvp.astralsorcery.common.block.tile.BlockChalice)1 LiquidInteraction (hellfirepvp.astralsorcery.common.crafting.recipe.LiquidInteraction)1 LiquidInteractionContext (hellfirepvp.astralsorcery.common.crafting.recipe.LiquidInteractionContext)1 PktPlayEffect (hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect)1 RaytraceAssist (hellfirepvp.astralsorcery.common.util.RaytraceAssist)1 Nonnull (javax.annotation.Nonnull)1 FluidStack (net.minecraftforge.fluids.FluidStack)1