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);
}
}
}
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;
}
Aggregations