172 lines
6.7 KiB
Java
172 lines
6.7 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import java.util.Collections;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.storage.loot.LootContext;
|
|
import net.minecraft.world.level.material.Fluid;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.tags.FluidTags;
|
|
import net.minecraft.world.level.pathfinder.PathComputationType;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import java.util.Random;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import com.google.common.collect.Lists;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import java.util.List;
|
|
import net.minecraft.world.level.material.FlowingFluid;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
|
|
public class LiquidBlock extends Block implements BucketPickup {
|
|
public static final IntegerProperty LEVEL;
|
|
protected final FlowingFluid fluid;
|
|
private final List<FluidState> stateCache;
|
|
|
|
protected LiquidBlock(final FlowingFluid coe, final Properties c) {
|
|
super(c);
|
|
this.fluid = coe;
|
|
(this.stateCache = Lists.newArrayList()).add(coe.getSource(false));
|
|
for (int integer4 = 1; integer4 < 8; ++integer4) {
|
|
this.stateCache.add(coe.getFlowing(8 - integer4, false));
|
|
}
|
|
this.stateCache.add(coe.getFlowing(8, true));
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)LiquidBlock.LEVEL, 0));
|
|
}
|
|
|
|
@Override
|
|
public void randomTick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
xd.getFluidState(fk).randomTick(xd, fk, random);
|
|
}
|
|
|
|
@Override
|
|
public boolean propagatesSkylightDown(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
|
|
return !this.fluid.is(FluidTags.LAVA);
|
|
}
|
|
|
|
@Override
|
|
public FluidState getFluidState(final BlockState byg) {
|
|
final int integer3 = byg.<Integer>getValue((Property<Integer>)LiquidBlock.LEVEL);
|
|
return this.stateCache.get(Math.min(integer3, 8));
|
|
}
|
|
|
|
@Override
|
|
public boolean skipRendering(final BlockState byg1, final BlockState byg2, final Direction fp) {
|
|
return byg2.getFluidState().getType().isSame(this.fluid);
|
|
}
|
|
|
|
@Override
|
|
public RenderShape getRenderShape(final BlockState byg) {
|
|
return RenderShape.INVISIBLE;
|
|
}
|
|
|
|
@Override
|
|
public List<ItemStack> getDrops(final BlockState byg, final LootContext.Builder a) {
|
|
return Collections.<ItemStack>emptyList();
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return Shapes.empty();
|
|
}
|
|
|
|
@Override
|
|
public int getTickDelay(final LevelReader bjw) {
|
|
return this.fluid.getTickDelay(bjw);
|
|
}
|
|
|
|
@Override
|
|
public void onPlace(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
|
|
if (this.shouldSpreadLiquid(bjt, fk, byg1)) {
|
|
bjt.getLiquidTicks().scheduleTick(fk, byg1.getFluidState().getType(), this.getTickDelay(bjt));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (byg1.getFluidState().isSource() || byg3.getFluidState().isSource()) {
|
|
bju.getLiquidTicks().scheduleTick(fk5, byg1.getFluidState().getType(), this.getTickDelay(bju));
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
public void neighborChanged(final BlockState byg, final Level bjt, final BlockPos fk3, final Block bpe, final BlockPos fk5, final boolean boolean6) {
|
|
if (this.shouldSpreadLiquid(bjt, fk3, byg)) {
|
|
bjt.getLiquidTicks().scheduleTick(fk3, byg.getFluidState().getType(), this.getTickDelay(bjt));
|
|
}
|
|
}
|
|
|
|
public boolean shouldSpreadLiquid(final Level bjt, final BlockPos fk, final BlockState byg) {
|
|
if (this.fluid.is(FluidTags.LAVA)) {
|
|
boolean boolean5 = false;
|
|
for (final Direction fp9 : Direction.values()) {
|
|
if (fp9 != Direction.DOWN && bjt.getFluidState(fk.relative(fp9)).is(FluidTags.WATER)) {
|
|
boolean5 = true;
|
|
break;
|
|
}
|
|
}
|
|
if (boolean5) {
|
|
final FluidState cog6 = bjt.getFluidState(fk);
|
|
if (cog6.isSource()) {
|
|
bjt.setBlockAndUpdate(fk, Blocks.OBSIDIAN.defaultBlockState());
|
|
this.fizz(bjt, fk);
|
|
return false;
|
|
}
|
|
if (cog6.getHeight(bjt, fk) >= 0.44444445f) {
|
|
bjt.setBlockAndUpdate(fk, Blocks.COBBLESTONE.defaultBlockState());
|
|
this.fizz(bjt, fk);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void fizz(final LevelAccessor bju, final BlockPos fk) {
|
|
bju.levelEvent(1501, fk, 0);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(LiquidBlock.LEVEL);
|
|
}
|
|
|
|
@Override
|
|
public Fluid takeLiquid(final LevelAccessor bju, final BlockPos fk, final BlockState byg) {
|
|
if (byg.<Integer>getValue((Property<Integer>)LiquidBlock.LEVEL) == 0) {
|
|
bju.setBlock(fk, Blocks.AIR.defaultBlockState(), 11);
|
|
return this.fluid;
|
|
}
|
|
return Fluids.EMPTY;
|
|
}
|
|
|
|
@Override
|
|
public void entityInside(final BlockState byg, final Level bjt, final BlockPos fk, final Entity akn) {
|
|
if (this.fluid.is(FluidTags.LAVA)) {
|
|
akn.setInLava();
|
|
}
|
|
}
|
|
|
|
static {
|
|
LEVEL = BlockStateProperties.LEVEL;
|
|
}
|
|
}
|