67 lines
2.4 KiB
Java
67 lines
2.4 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.tags.FluidTags;
|
|
import net.minecraft.core.Vec3i;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class ConcretePowderBlock extends FallingBlock {
|
|
private final BlockState concrete;
|
|
|
|
public ConcretePowderBlock(final Block bpe, final Properties c) {
|
|
super(c);
|
|
this.concrete = bpe.defaultBlockState();
|
|
}
|
|
|
|
@Override
|
|
public void onLand(final Level bjt, final BlockPos fk, final BlockState byg3, final BlockState byg4) {
|
|
if (canSolidify(byg4)) {
|
|
bjt.setBlock(fk, this.concrete, 3);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
final BlockGetter bjd3 = bcn.getLevel();
|
|
final BlockPos fk4 = bcn.getClickedPos();
|
|
if (canSolidify(bjd3.getBlockState(fk4)) || touchesLiquid(bjd3, fk4)) {
|
|
return this.concrete;
|
|
}
|
|
return super.getStateForPlacement(bcn);
|
|
}
|
|
|
|
private static boolean touchesLiquid(final BlockGetter bjd, final BlockPos fk) {
|
|
boolean boolean3 = false;
|
|
final BlockPos.MutableBlockPos a4 = new BlockPos.MutableBlockPos(fk);
|
|
for (final Direction fp8 : Direction.values()) {
|
|
BlockState byg9 = bjd.getBlockState(a4);
|
|
if (fp8 != Direction.DOWN || canSolidify(byg9)) {
|
|
a4.set(fk).move(fp8);
|
|
byg9 = bjd.getBlockState(a4);
|
|
if (canSolidify(byg9) && !byg9.isFaceSturdy(bjd, fk, fp8.getOpposite())) {
|
|
boolean3 = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return boolean3;
|
|
}
|
|
|
|
private static boolean canSolidify(final BlockState byg) {
|
|
return byg.getFluidState().is(FluidTags.WATER);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (touchesLiquid(bju, fk5)) {
|
|
return this.concrete;
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
}
|