minecraft-source/src/net/minecraft/world/level/ClipContext.java

80 lines
2.5 KiB
Java
Raw Normal View History

2020-07-22 06:23:34 +01:00
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;
2020-07-22 06:25:47 +01:00
public ClipContext(final Vec3 cvi1, final Vec3 cvi2, final Block a, final Fluid b, final Entity akn) {
this.from = cvi1;
this.to = cvi2;
2020-07-22 06:23:34 +01:00
this.block = a;
this.fluid = b;
2020-07-22 06:25:47 +01:00
this.collisionContext = CollisionContext.of(akn);
2020-07-22 06:23:34 +01:00
}
public Vec3 getTo() {
return this.to;
}
public Vec3 getFrom() {
return this.from;
}
2020-07-22 06:25:47 +01:00
public VoxelShape getBlockShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
return this.block.get(byg, bjd, fk, this.collisionContext);
2020-07-22 06:23:34 +01:00
}
2020-07-22 06:25:47 +01:00
public VoxelShape getFluidShape(final FluidState cog, final BlockGetter bjd, final BlockPos fk) {
return this.fluid.canPick(cog) ? cog.getShape(bjd, fk) : Shapes.empty();
2020-07-22 06:23:34 +01:00
}
public enum Block implements ShapeGetter {
COLLIDER(BlockState::getCollisionShape),
OUTLINE(BlockState::getShape);
private final ShapeGetter shapeGetter;
private Block(final ShapeGetter c) {
this.shapeGetter = c;
}
@Override
2020-07-22 06:25:47 +01:00
public VoxelShape get(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
return this.shapeGetter.get(byg, bjd, fk, cvn);
2020-07-22 06:23:34 +01:00
}
}
public enum Fluid {
2020-07-22 06:25:47 +01:00
NONE(cog -> false),
2020-07-22 06:23:34 +01:00
SOURCE_ONLY(FluidState::isSource),
2020-07-22 06:25:47 +01:00
ANY(cog -> !cog.isEmpty());
2020-07-22 06:23:34 +01:00
private final Predicate<FluidState> canPick;
private Fluid(final Predicate<FluidState> predicate) {
this.canPick = predicate;
}
2020-07-22 06:25:47 +01:00
public boolean canPick(final FluidState cog) {
return this.canPick.test(cog);
2020-07-22 06:23:34 +01:00
}
}
public interface ShapeGetter {
2020-07-22 06:25:47 +01:00
VoxelShape get(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn);
2020-07-22 06:23:34 +01:00
}
}