80 lines
2.5 KiB
Java
80 lines
2.5 KiB
Java
package net.minecraft.world.level;
|
|
|
|
import java.util.function.Predicate;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
public class ClipContext {
|
|
private final Vec3 from;
|
|
private final Vec3 to;
|
|
private final Block block;
|
|
private final Fluid fluid;
|
|
private final CollisionContext collisionContext;
|
|
|
|
public ClipContext(final Vec3 cvi1, final Vec3 cvi2, final Block a, final Fluid b, final Entity akn) {
|
|
this.from = cvi1;
|
|
this.to = cvi2;
|
|
this.block = a;
|
|
this.fluid = b;
|
|
this.collisionContext = CollisionContext.of(akn);
|
|
}
|
|
|
|
public Vec3 getTo() {
|
|
return this.to;
|
|
}
|
|
|
|
public Vec3 getFrom() {
|
|
return this.from;
|
|
}
|
|
|
|
public VoxelShape getBlockShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
|
|
return this.block.get(byg, bjd, fk, this.collisionContext);
|
|
}
|
|
|
|
public VoxelShape getFluidShape(final FluidState cog, final BlockGetter bjd, final BlockPos fk) {
|
|
return this.fluid.canPick(cog) ? cog.getShape(bjd, fk) : Shapes.empty();
|
|
}
|
|
|
|
public enum Block implements ShapeGetter {
|
|
COLLIDER(BlockState::getCollisionShape),
|
|
OUTLINE(BlockState::getShape);
|
|
|
|
private final ShapeGetter shapeGetter;
|
|
|
|
private Block(final ShapeGetter c) {
|
|
this.shapeGetter = c;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape get(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return this.shapeGetter.get(byg, bjd, fk, cvn);
|
|
}
|
|
}
|
|
|
|
public enum Fluid {
|
|
NONE(cog -> false),
|
|
SOURCE_ONLY(FluidState::isSource),
|
|
ANY(cog -> !cog.isEmpty());
|
|
|
|
private final Predicate<FluidState> canPick;
|
|
|
|
private Fluid(final Predicate<FluidState> predicate) {
|
|
this.canPick = predicate;
|
|
}
|
|
|
|
public boolean canPick(final FluidState cog) {
|
|
return this.canPick.test(cog);
|
|
}
|
|
}
|
|
|
|
public interface ShapeGetter {
|
|
VoxelShape get(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn);
|
|
}
|
|
}
|