use of net.minecraft.fluid.FlowingFluid in project Ceramics by KnightMiner.
the class ClayBucketItem method tryPlaceContainedLiquid.
// TODO: possibly migrate to the Forge method
@SuppressWarnings("deprecation")
private boolean tryPlaceContainedLiquid(@Nullable PlayerEntity player, World world, BlockPos pos, ItemStack stack, @Nullable BlockRayTraceResult trace) {
Fluid fluidStack = this.getFluid(stack);
Fluid fluid = fluidStack.getFluid();
if (!(fluid instanceof FlowingFluid)) {
return false;
}
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
boolean replaceable = state.isReplaceable(fluid);
if (state.isAir(world, pos) || replaceable || block instanceof ILiquidContainer && ((ILiquidContainer) block).canContainFluid(world, pos, state, fluid)) {
if (world.getDimensionType().isUltrawarm() && fluid.isIn(FluidTags.WATER)) {
world.playSound(player, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
for (int l = 0; l < 8; ++l) {
world.addParticle(ParticleTypes.LARGE_SMOKE, pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), 0.0D, 0.0D, 0.0D);
}
} else if (block instanceof ILiquidContainer && fluid == Fluids.WATER) {
if (((ILiquidContainer) block).receiveFluid(world, pos, state, ((FlowingFluid) fluid).getStillFluidState(false))) {
this.playEmptySound(fluid, player, world, pos);
}
} else {
if (!world.isRemote() && replaceable && !state.getMaterial().isLiquid()) {
world.destroyBlock(pos, true);
}
this.playEmptySound(fluid, player, world, pos);
world.setBlockState(pos, fluid.getDefaultState().getBlockState(), 11);
}
return true;
}
if (trace == null) {
return false;
}
return this.tryPlaceContainedLiquid(player, world, trace.getPos().offset(trace.getFace()), stack, null);
}
use of net.minecraft.fluid.FlowingFluid in project Mekanism by mekanism.
the class MekanismUtils method getFluidsIn.
/**
* Similar in concept to {@link net.minecraft.entity.Entity#updateFluidHeightAndDoFluidPushing(ITag, double)} except calculates if a given portion of the player is in
* the fluids.
*/
public static Map<Fluid, FluidInDetails> getFluidsIn(PlayerEntity player, UnaryOperator<AxisAlignedBB> modifyBoundingBox) {
AxisAlignedBB bb = modifyBoundingBox.apply(player.getBoundingBox().deflate(0.001));
int xMin = MathHelper.floor(bb.minX);
int xMax = MathHelper.ceil(bb.maxX);
int yMin = MathHelper.floor(bb.minY);
int yMax = MathHelper.ceil(bb.maxY);
int zMin = MathHelper.floor(bb.minZ);
int zMax = MathHelper.ceil(bb.maxZ);
if (!player.level.hasChunksAt(xMin, yMin, zMin, xMax, yMax, zMax)) {
// If the position isn't actually loaded, just return there isn't any fluids
return Collections.emptyMap();
}
Map<Fluid, FluidInDetails> fluidsIn = new HashMap<>();
BlockPos.Mutable mutablePos = new BlockPos.Mutable();
for (int x = xMin; x < xMax; ++x) {
for (int y = yMin; y < yMax; ++y) {
for (int z = zMin; z < zMax; ++z) {
mutablePos.set(x, y, z);
FluidState fluidState = player.level.getFluidState(mutablePos);
if (!fluidState.isEmpty()) {
double fluidY = y + fluidState.getHeight(player.level, mutablePos);
if (bb.minY <= fluidY) {
// The fluid intersects the bounding box
Fluid fluid = fluidState.getType();
if (fluid instanceof FlowingFluid) {
// Almost always will be flowing fluid but check just in case
// and if it is grab the source state to not have duplicates
fluid = ((FlowingFluid) fluid).getSource();
}
FluidInDetails details = fluidsIn.computeIfAbsent(fluid, f -> new FluidInDetails());
details.positions.add(mutablePos.immutable());
double actualFluidHeight;
if (fluidY > bb.maxY) {
// Fluid goes past the top of the bounding box, limit it to the top
// We do the max of the bottom of the bounding box and our current block so that
// if we are floating above the bottom we don't take the area below us into account
actualFluidHeight = bb.maxY - Math.max(bb.minY, y);
} else {
// We do the max of the bottom of the bounding box and our current block so that
// if we are floating above the bottom we don't take the area below us into account
actualFluidHeight = fluidY - Math.max(bb.minY, y);
}
details.heights.merge(ChunkPos.asLong(x, z), actualFluidHeight, Double::sum);
}
}
}
}
}
return fluidsIn;
}
use of net.minecraft.fluid.FlowingFluid in project MCMOD-Industria by M-Marvin.
the class ItemFluidBucket method emptyBucket.
@SuppressWarnings("deprecation")
public boolean emptyBucket(@Nullable PlayerEntity player, World worldIn, BlockPos posIn, @Nullable BlockRayTraceResult rayTrace) {
if (!(getFluid() instanceof FlowingFluid)) {
return false;
} else {
BlockState blockstate = worldIn.getBlockState(posIn);
Block block = blockstate.getBlock();
Material material = blockstate.getMaterial();
boolean flag = blockstate.canBeReplaced(getFluid());
boolean flag1 = blockstate.isAir() || flag || block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(worldIn, posIn, blockstate, getFluid());
if (!flag1) {
return rayTrace != null && this.emptyBucket(player, worldIn, rayTrace.getBlockPos().relative(rayTrace.getDirection()), (BlockRayTraceResult) null);
} else if (!canPlaceInNether && worldIn.dimensionType().ultraWarm()) {
int i = posIn.getX();
int j = posIn.getY();
int k = posIn.getZ();
worldIn.playSound(player, posIn, SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.random.nextFloat() - worldIn.random.nextFloat()) * 0.8F);
for (int l = 0; l < 8; ++l) {
worldIn.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
}
return true;
} else if (block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(worldIn, posIn, blockstate, getFluid())) {
((ILiquidContainer) block).placeLiquid(worldIn, posIn, blockstate, ((FlowingFluid) getFluid()).getSource(false));
this.playEmptySound(player, worldIn, posIn);
return true;
} else {
if (!worldIn.isClientSide && flag && !material.isLiquid()) {
worldIn.destroyBlock(posIn, true);
}
if (!worldIn.setBlock(posIn, getFluid().defaultFluidState().createLegacyBlock(), 11) && !blockstate.getFluidState().isSource()) {
return false;
} else {
this.playEmptySound(player, worldIn, posIn);
return true;
}
}
}
}
Aggregations