| 1 | package net.minecraft.world.level.material;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.core.Direction;
|
| 6 | import net.minecraft.core.Holder;
|
| 7 | import net.minecraft.core.TypedInstance;
|
| 8 | import net.minecraft.core.particles.ParticleOptions;
|
| 9 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 10 | import net.minecraft.server.level.ServerLevel;
|
| 11 | import net.minecraft.util.RandomSource;
|
| 12 | import net.minecraft.world.entity.Entity;
|
| 13 | import net.minecraft.world.entity.InsideBlockEffectApplier;
|
| 14 | import net.minecraft.world.level.BlockGetter;
|
| 15 | import net.minecraft.world.level.Level;
|
| 16 | import net.minecraft.world.level.block.state.BlockState;
|
| 17 | import net.minecraft.world.level.block.state.StateHolder;
|
| 18 | import net.minecraft.world.level.block.state.properties.Property;
|
| 19 | import net.minecraft.world.phys.AABB;
|
| 20 | import net.minecraft.world.phys.Vec3;
|
| 21 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 22 | import org.jspecify.annotations.Nullable;
|
| 23 |
|
| 24 | public final class FluidState extends StateHolder<Fluid, FluidState> implements TypedInstance<Fluid> {
|
| 25 | public static final Codec<FluidState> CODEC = codec(BuiltInRegistries.FLUID.byNameCodec(), Fluid::defaultFluidState, Fluid::getStateDefinition).stable();
|
| 26 | public static final int AMOUNT_MAX = 9;
|
| 27 | public static final int AMOUNT_FULL = 8;
|
| 28 |
|
| 29 | public FluidState(final Fluid owner, final Property<?>[] propertyKeys, final Comparable<?>[] propertyValues) {
|
| 30 | super(owner, propertyKeys, propertyValues);
|
| 31 | }
|
| 32 |
|
| 33 | public Fluid getType() {
|
| 34 | return this.owner;
|
| 35 | }
|
| 36 |
|
| 37 | public boolean isSource() {
|
| 38 | return this.getType().isSource(this);
|
| 39 | }
|
| 40 |
|
| 41 | public boolean isSourceOfType(final Fluid fluidType) {
|
| 42 | return this.owner == fluidType && this.owner.isSource(this);
|
| 43 | }
|
| 44 |
|
| 45 | public boolean isEmpty() {
|
| 46 | return this.getType().isEmpty();
|
| 47 | }
|
| 48 |
|
| 49 | public float getHeight(final BlockGetter level, final BlockPos pos) {
|
| 50 | return this.getType().getHeight(this, level, pos);
|
| 51 | }
|
| 52 |
|
| 53 | public float getHeightForCamera(final BlockGetter level, final BlockPos pos) {
|
| 54 | if (this.isSource()) {
|
| 55 | BlockPos posAbove = pos.above();
|
| 56 | if (level.getBlockState(posAbove).isFaceSturdy(level, posAbove, Direction.DOWN)) {
|
| 57 | return 1.0F;
|
| 58 | }
|
| 59 | }
|
| 60 |
|
| 61 | return this.getHeight(level, pos);
|
| 62 | }
|
| 63 |
|
| 64 | public float getOwnHeight() {
|
| 65 | return this.getType().getOwnHeight(this);
|
| 66 | }
|
| 67 |
|
| 68 | public boolean isFull() {
|
| 69 | return this.getAmount() == 8;
|
| 70 | }
|
| 71 |
|
| 72 | public int getAmount() {
|
| 73 | return this.getType().getAmount(this);
|
| 74 | }
|
| 75 |
|
| 76 | public boolean shouldRenderBackwardUpFace(final BlockGetter level, final BlockPos above) {
|
| 77 | for (int ox = -1; ox <= 1; ox++) {
|
| 78 | for (int oz = -1; oz <= 1; oz++) {
|
| 79 | BlockPos offset = above.offset(ox, 0, oz);
|
| 80 | FluidState fluidState = level.getFluidState(offset);
|
| 81 | if (!fluidState.getType().isSame(this.getType()) && !level.getBlockState(offset).isSolidRender()) {
|
| 82 | return true;
|
| 83 | }
|
| 84 | }
|
| 85 | }
|
| 86 |
|
| 87 | return false;
|
| 88 | }
|
| 89 |
|
| 90 | public void tick(final ServerLevel level, final BlockPos pos, final BlockState blockState) {
|
| 91 | this.getType().tick(level, pos, blockState, this);
|
| 92 | }
|
| 93 |
|
| 94 | public void animateTick(final Level level, final BlockPos pos, final RandomSource random) {
|
| 95 | this.getType().animateTick(level, pos, this, random);
|
| 96 | }
|
| 97 |
|
| 98 | public boolean isRandomlyTicking() {
|
| 99 | return this.getType().isRandomlyTicking();
|
| 100 | }
|
| 101 |
|
| 102 | public void randomTick(final ServerLevel level, final BlockPos pos, final RandomSource random) {
|
| 103 | this.getType().randomTick(level, pos, this, random);
|
| 104 | }
|
| 105 |
|
| 106 | public Vec3 getFlow(final BlockGetter level, final BlockPos pos) {
|
| 107 | return this.getType().getFlow(level, pos, this);
|
| 108 | }
|
| 109 |
|
| 110 | public BlockState createLegacyBlock() {
|
| 111 | return this.getType().createLegacyBlock(this);
|
| 112 | }
|
| 113 |
|
| 114 | public @Nullable ParticleOptions getDripParticle() {
|
| 115 | return this.getType().getDripParticle();
|
| 116 | }
|
| 117 |
|
| 118 | @Override
|
| 119 | public Holder<Fluid> typeHolder() {
|
| 120 | return this.getType().builtInRegistryHolder();
|
| 121 | }
|
| 122 |
|
| 123 | public float getExplosionResistance() {
|
| 124 | return this.getType().getExplosionResistance();
|
| 125 | }
|
| 126 |
|
| 127 | public boolean canBeReplacedWith(final BlockGetter level, final BlockPos pos, final Fluid other, final Direction direction) {
|
| 128 | return this.getType().canBeReplacedWith(this, level, pos, other, direction);
|
| 129 | }
|
| 130 |
|
| 131 | public VoxelShape getShape(final BlockGetter level, final BlockPos pos) {
|
| 132 | return this.getType().getShape(this, level, pos);
|
| 133 | }
|
| 134 |
|
| 135 | public @Nullable AABB getAABB(final BlockGetter level, final BlockPos pos) {
|
| 136 | return this.getType().getAABB(this, level, pos);
|
| 137 | }
|
| 138 |
|
| 139 | public void entityInside(final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier) {
|
| 140 | this.getType().entityInside(level, pos, entity, effectApplier);
|
| 141 | }
|
| 142 | }
|
| 143 |
|