package net.minecraft.world.level; import net.minecraft.util.Mth; import java.util.function.Function; import java.util.function.BiFunction; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.Vec3; import net.minecraft.core.Direction; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.block.state.BlockState; import javax.annotation.Nullable; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.core.BlockPos; public interface BlockGetter { @Nullable BlockEntity getBlockEntity(final BlockPos fk); BlockState getBlockState(final BlockPos fk); FluidState getFluidState(final BlockPos fk); default int getLightEmission(final BlockPos fk) { return this.getBlockState(fk).getLightEmission(); } default int getMaxLightLevel() { return 15; } default int getMaxBuildHeight() { return 256; } default BlockHitResult clip(final ClipContext bjg) { final BlockState byg4; final FluidState cog5; final Vec3 cvi6; final Vec3 cvi7; final VoxelShape cwc8; final BlockHitResult cvd9; final VoxelShape cwc9; final BlockHitResult cvd10; final double double12; final double double13; final Vec3 cvi8; return BlockGetter.traverseBlocks(bjg, (bjg, fk) -> { byg4 = this.getBlockState(fk); cog5 = this.getFluidState(fk); cvi6 = bjg.getFrom(); cvi7 = bjg.getTo(); cwc8 = bjg.getBlockShape(byg4, this, fk); cvd9 = this.clipWithInteractionOverride(cvi6, cvi7, fk, cwc8, byg4); cwc9 = bjg.getFluidShape(cog5, this, fk); cvd10 = cwc9.clip(cvi6, cvi7, fk); double12 = ((cvd9 == null) ? Double.MAX_VALUE : bjg.getFrom().distanceToSqr(cvd9.getLocation())); double13 = ((cvd10 == null) ? Double.MAX_VALUE : bjg.getFrom().distanceToSqr(cvd10.getLocation())); return (double12 <= double13) ? cvd9 : cvd10; }, bjg -> { cvi8 = bjg.getFrom().subtract(bjg.getTo()); return BlockHitResult.miss(bjg.getTo(), Direction.getNearest(cvi8.x, cvi8.y, cvi8.z), new BlockPos(bjg.getTo())); }); } @Nullable default BlockHitResult clipWithInteractionOverride(final Vec3 cvi1, final Vec3 cvi2, final BlockPos fk, final VoxelShape cwc, final BlockState byg) { final BlockHitResult cvd7 = cwc.clip(cvi1, cvi2, fk); if (cvd7 != null) { final BlockHitResult cvd8 = byg.getInteractionShape(this, fk).clip(cvi1, cvi2, fk); if (cvd8 != null && cvd8.getLocation().subtract(cvi1).lengthSqr() < cvd7.getLocation().subtract(cvi1).lengthSqr()) { return cvd7.withDirection(cvd8.getDirection()); } } return cvd7; } default T traverseBlocks(final ClipContext bjg, final BiFunction biFunction, final Function function) { final Vec3 cvi4 = bjg.getFrom(); final Vec3 cvi5 = bjg.getTo(); if (cvi4.equals(cvi5)) { return function.apply(bjg); } final double double6 = Mth.lerp(-1.0E-7, cvi5.x, cvi4.x); final double double7 = Mth.lerp(-1.0E-7, cvi5.y, cvi4.y); final double double8 = Mth.lerp(-1.0E-7, cvi5.z, cvi4.z); final double double9 = Mth.lerp(-1.0E-7, cvi4.x, cvi5.x); final double double10 = Mth.lerp(-1.0E-7, cvi4.y, cvi5.y); final double double11 = Mth.lerp(-1.0E-7, cvi4.z, cvi5.z); int integer18 = Mth.floor(double9); int integer19 = Mth.floor(double10); int integer20 = Mth.floor(double11); final BlockPos.MutableBlockPos a21 = new BlockPos.MutableBlockPos(integer18, integer19, integer20); final T object22 = biFunction.apply(bjg, a21); if (object22 != null) { return object22; } final double double12 = double6 - double9; final double double13 = double7 - double10; final double double14 = double8 - double11; final int integer21 = Mth.sign(double12); final int integer22 = Mth.sign(double13); final int integer23 = Mth.sign(double14); final double double15 = (integer21 == 0) ? Double.MAX_VALUE : (integer21 / double12); final double double16 = (integer22 == 0) ? Double.MAX_VALUE : (integer22 / double13); final double double17 = (integer23 == 0) ? Double.MAX_VALUE : (integer23 / double14); double double18 = double15 * ((integer21 > 0) ? (1.0 - Mth.frac(double9)) : Mth.frac(double9)); double double19 = double16 * ((integer22 > 0) ? (1.0 - Mth.frac(double10)) : Mth.frac(double10)); double double20 = double17 * ((integer23 > 0) ? (1.0 - Mth.frac(double11)) : Mth.frac(double11)); while (double18 <= 1.0 || double19 <= 1.0 || double20 <= 1.0) { if (double18 < double19) { if (double18 < double20) { integer18 += integer21; double18 += double15; } else { integer20 += integer23; double20 += double17; } } else if (double19 < double20) { integer19 += integer22; double19 += double16; } else { integer20 += integer23; double20 += double17; } final T object23 = biFunction.apply(bjg, a21.set(integer18, integer19, integer20)); if (object23 != null) { return object23; } } return function.apply(bjg); } }