net.minecraft.util.math.shapes.VoxelShape Java Examples
The following examples show how to use
net.minecraft.util.math.shapes.VoxelShape.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubHitVoxelShape.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Nullable @Override public BlockRayTraceResult rayTrace(Vec3d start, Vec3d end, BlockPos pos) { CuboidRayTraceResult closest = null; double dist = Double.MAX_VALUE; for (Pair<IndexedCuboid6, VoxelShape> cuboidShape : cuboidShapes) { CuboidRayTraceResult hit = rayTrace(start, end, pos, cuboidShape.getLeft(), cuboidShape.getRight()); if (hit != null && dist > hit.dist) { closest = hit; dist = hit.dist; } } return closest; }
Example #2
Source File: SpawnableBlocksHelper.java From BoundingBoxOutlineReloaded with MIT License | 5 votes |
static boolean isSpawnable(World world, BlockPos pos, BlockState spawnBlockState, BlockState upperBlockState) { VoxelShape collisionShape = upperBlockState.getCollisionShape(world, pos); boolean isNether = world.dimension.isNether(); return spawnBlockState.canEntitySpawn(world, pos.down(), isNether ? EntityType.ZOMBIE_PIGMAN : entityType) && !Block.doesSideFillSquare(collisionShape, Direction.UP) && !upperBlockState.canProvidePower() && !upperBlockState.isIn(BlockTags.RAILS) && collisionShape.getEnd(Direction.Axis.Y) <= 0 && upperBlockState.getFluidState().isEmpty() && (isNether || world.getLightFor(LightType.BLOCK, pos) <= 7); }
Example #3
Source File: VoxelShapeCache.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
private static MutablePair<AxisAlignedBB, Cuboid6> getReverse(VoxelShape shape) { MutablePair<AxisAlignedBB, Cuboid6> entry = shapeToBBCuboid.getIfPresent(shape); if (entry == null) { entry = new MutablePair<>(); shapeToBBCuboid.put(shape, entry); } return entry; }
Example #4
Source File: VoxelShapeCache.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static Cuboid6 getCuboid(VoxelShape shape) { MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape); if (entry.getRight() == null) { entry.setRight(new Cuboid6(// I hope this is okay, don't want to rely on AABB cache. shape.getStart(Direction.Axis.X), shape.getStart(Direction.Axis.Y), shape.getStart(Direction.Axis.Z),// shape.getEnd(Direction.Axis.X), shape.getEnd(Direction.Axis.Y), shape.getEnd(Direction.Axis.Z)// )); } return entry.getRight(); }
Example #5
Source File: VoxelShapeCache.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static AxisAlignedBB getAABB(VoxelShape shape) { MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape); if (entry.getLeft() == null) { entry.setLeft(shape.getBoundingBox()); } return entry.getLeft(); }
Example #6
Source File: VoxelShapeCache.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static VoxelShape getShape(Cuboid6 cuboid) { VoxelShape shape = cuboidToShapeCache.getIfPresent(cuboid); if (shape == null) { shape = VoxelShapes.create(cuboid.min.x, cuboid.min.y, cuboid.min.z, cuboid.max.x, cuboid.max.y, cuboid.max.z); cuboidToShapeCache.put(cuboid, shape); MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape); if (entry.getRight() == null) { entry.setRight(cuboid); } } return shape; }
Example #7
Source File: VoxelShapeCache.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static VoxelShape getShape(AxisAlignedBB aabb) { VoxelShape shape = bbToShapeCache.getIfPresent(aabb); if (shape == null) { shape = VoxelShapes.create(aabb); bbToShapeCache.put(aabb, shape); MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape); if (entry.getLeft() == null) { entry.setLeft(aabb); } } return shape; }
Example #8
Source File: SubHitVoxelShape.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
private CuboidRayTraceResult rayTrace(Vec3d start, Vec3d end, BlockPos pos, IndexedCuboid6 cuboid, VoxelShape shape) { BlockRayTraceResult hit = shape.rayTrace(start, end, pos); if (hit != null) { Vector3 hitVec = new Vector3(hit.getHitVec()); return new CuboidRayTraceResult(hitVec, hit.getFace(), pos, hit.isInside(), cuboid, hitVec.copy().subtract(start).magSquared()); } return null; }
Example #9
Source File: SubHitVoxelShape.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * @param shape The base advertised VoxelShape. (Collision / w/e) * @param cuboids Any SubHit's. */ public SubHitVoxelShape(VoxelShape shape, List<IndexedCuboid6> cuboids) { super(shape.part); this.shape = shape; cuboidShapes = cuboids.stream()// .map(e -> Pair.of(e, VoxelShapeCache.getShape(e)))// .collect(Collectors.toList()); }
Example #10
Source File: RayTracer.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static BlockRayTraceResult retraceBlock(IBlockReader world, PlayerEntity player, BlockPos pos) { Vec3d startVec = getStartVec(player); Vec3d endVec = getEndVec(player); BlockState state = world.getBlockState(pos); VoxelShape baseShape = state.getShape(world, pos); BlockRayTraceResult baseTraceResult = baseShape.rayTrace(startVec, endVec, pos); if (baseTraceResult != null) { BlockRayTraceResult raytraceTraceShape = state.getRaytraceShape(world, pos).rayTrace(startVec, endVec, pos); if (raytraceTraceShape != null) { return raytraceTraceShape; } } return baseTraceResult; }
Example #11
Source File: MergedVoxelShapeHolder.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public VoxelShape update(Collection<T> things) { partCache.clear(); for (T thing : things) { partCache.add(extractor.apply(thing)); } if (!partCache.equals(shapeParts) || mergedShape == null) { shapeParts.clear(); shapeParts.addAll(partCache); //Same as VoxelShapes.or(VoxelShapes.empty(), shapeParts.toArray()); Except we skip useless array creation. VoxelShape merged = shapeParts.stream().reduce(VoxelShapes.empty(), VoxelShapes::or); mergedShape = postProcess.apply(merged); } return mergedShape; }
Example #12
Source File: BlockEnderChest.java From EnderStorage with MIT License | 5 votes |
@Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { VoxelShape shape = CHEST_SHAPE; TileEntity t = worldIn.getTileEntity(pos); if (t instanceof TileEnderChest) { TileEnderChest tile = (TileEnderChest) t; shape = SHAPES[tile.rotation][tile.getRadianLidAngle(0) >= 0 ? 0 : 1]; } return shape; }
Example #13
Source File: BlockEnderTank.java From EnderStorage with MIT License | 5 votes |
@Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { VoxelShape shape = TANK_SHAPE; TileEntity t = worldIn.getTileEntity(pos); if (t instanceof TileEnderTank) { TileEnderTank tile = (TileEnderTank) t; shape = SHAPES[tile.rotation]; } return shape; }
Example #14
Source File: MinersLight.java From MiningGadgets with MIT License | 4 votes |
@Override public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return VoxelShapes.empty(); }
Example #15
Source File: MergedVoxelShapeHolder.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 4 votes |
public MergedVoxelShapeHolder<T> setPostProcessHook(Function<VoxelShape, VoxelShape> postProcess) { this.postProcess = postProcess; return this; }
Example #16
Source File: MergedVoxelShapeHolder.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 4 votes |
public MergedVoxelShapeHolder<T> setExtractor(Function<T, VoxelShape> extractor) { this.extractor = extractor; return this; }
Example #17
Source File: Cuboid6.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 4 votes |
public VoxelShape shape() { return VoxelShapeCache.getShape(this); }
Example #18
Source File: ChoppingBlock.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return SHAPE; }
Example #19
Source File: DryingRackBlock.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return (state.get(FACING).getHorizontalIndex() % 2) == 0 ? shape1 : shape2; }
Example #20
Source File: MinersLight.java From MiningGadgets with MIT License | 4 votes |
/** * @deprecated call via {@link BlockState#getPushReaction()} whenever possible. Implementing/overriding is fine. */ @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext selectionContext) { return SHAPE; }