88 lines
3.8 KiB
Java
88 lines
3.8 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import java.util.Queue;
|
|
import net.minecraft.world.level.material.Material;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.tags.FluidTags;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.util.Tuple;
|
|
import com.google.common.collect.Lists;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class SpongeBlock extends Block {
|
|
protected SpongeBlock(final Properties c) {
|
|
super(c);
|
|
}
|
|
|
|
@Override
|
|
public void onPlace(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
|
|
if (byg4.getBlock() == byg1.getBlock()) {
|
|
return;
|
|
}
|
|
this.tryAbsorbWater(bjt, fk);
|
|
}
|
|
|
|
@Override
|
|
public void neighborChanged(final BlockState byg, final Level bjt, final BlockPos fk3, final Block bpe, final BlockPos fk5, final boolean boolean6) {
|
|
this.tryAbsorbWater(bjt, fk3);
|
|
super.neighborChanged(byg, bjt, fk3, bpe, fk5, boolean6);
|
|
}
|
|
|
|
protected void tryAbsorbWater(final Level bjt, final BlockPos fk) {
|
|
if (this.removeWaterBreadthFirstSearch(bjt, fk)) {
|
|
bjt.setBlock(fk, Blocks.WET_SPONGE.defaultBlockState(), 2);
|
|
bjt.levelEvent(2001, fk, Block.getId(Blocks.WATER.defaultBlockState()));
|
|
}
|
|
}
|
|
|
|
private boolean removeWaterBreadthFirstSearch(final Level bjt, final BlockPos fk) {
|
|
final Queue<Tuple<BlockPos, Integer>> queue4 = Lists.newLinkedList();
|
|
queue4.add(new Tuple<BlockPos, Integer>(fk, 0));
|
|
int integer5 = 0;
|
|
while (!queue4.isEmpty()) {
|
|
final Tuple<BlockPos, Integer> abz6 = queue4.poll();
|
|
final BlockPos fk2 = abz6.getA();
|
|
final int integer6 = abz6.getB();
|
|
for (final Direction fp12 : Direction.values()) {
|
|
final BlockPos fk3 = fk2.relative(fp12);
|
|
final BlockState byg14 = bjt.getBlockState(fk3);
|
|
final FluidState cog15 = bjt.getFluidState(fk3);
|
|
final Material cok16 = byg14.getMaterial();
|
|
if (cog15.is(FluidTags.WATER)) {
|
|
if (byg14.getBlock() instanceof BucketPickup && ((BucketPickup)byg14.getBlock()).takeLiquid(bjt, fk3, byg14) != Fluids.EMPTY) {
|
|
++integer5;
|
|
if (integer6 < 6) {
|
|
queue4.add(new Tuple<BlockPos, Integer>(fk3, integer6 + 1));
|
|
}
|
|
}
|
|
else if (byg14.getBlock() instanceof LiquidBlock) {
|
|
bjt.setBlock(fk3, Blocks.AIR.defaultBlockState(), 3);
|
|
++integer5;
|
|
if (integer6 < 6) {
|
|
queue4.add(new Tuple<BlockPos, Integer>(fk3, integer6 + 1));
|
|
}
|
|
}
|
|
else if (cok16 == Material.WATER_PLANT || cok16 == Material.REPLACEABLE_WATER_PLANT) {
|
|
final BlockEntity bwi17 = byg14.getBlock().isEntityBlock() ? bjt.getBlockEntity(fk3) : null;
|
|
Block.dropResources(byg14, bjt, fk3, bwi17);
|
|
bjt.setBlock(fk3, Blocks.AIR.defaultBlockState(), 3);
|
|
++integer5;
|
|
if (integer6 < 6) {
|
|
queue4.add(new Tuple<BlockPos, Integer>(fk3, integer6 + 1));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (integer5 > 64) {
|
|
break;
|
|
}
|
|
}
|
|
return integer5 > 0;
|
|
}
|
|
}
|