105 lines
3.3 KiB
Java
105 lines
3.3 KiB
Java
/*
|
|
* Copyright (c) 2021 TeamMoeg
|
|
*
|
|
* This file is part of Steam Powered.
|
|
*
|
|
* Steam Powered is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, version 3.
|
|
*
|
|
* Steam Powered is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Steam Powered. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package com.teammoeg.steampowered.block;
|
|
|
|
import com.simibubi.create.foundation.utility.VoxelShaper;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.util.Direction;
|
|
import net.minecraft.util.Direction.Axis;
|
|
import net.minecraft.util.math.shapes.IBooleanFunction;
|
|
import net.minecraft.util.math.shapes.VoxelShape;
|
|
import net.minecraft.util.math.shapes.VoxelShapes;
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
import static net.minecraft.util.Direction.UP;
|
|
|
|
public class SPShapes {
|
|
|
|
// From create:AllShapes
|
|
public static Builder shape(VoxelShape shape) {
|
|
return new Builder(shape);
|
|
}
|
|
|
|
|
|
public static Builder shape(double x1, double y1, double z1, double x2, double y2, double z2) {
|
|
return shape(cuboid(x1, y1, z1, x2, y2, z2));
|
|
}
|
|
|
|
public static VoxelShape cuboid(double x1, double y1, double z1, double x2, double y2, double z2) {
|
|
return Block.box(x1, y1, z1, x2, y2, z2);
|
|
}
|
|
|
|
public static class Builder {
|
|
VoxelShape shape;
|
|
|
|
public Builder(VoxelShape shape) {
|
|
this.shape = shape;
|
|
}
|
|
|
|
public Builder add(VoxelShape shape) {
|
|
this.shape = VoxelShapes.or(this.shape, shape);
|
|
return this;
|
|
}
|
|
|
|
public Builder add(double x1, double y1, double z1, double x2, double y2, double z2) {
|
|
return add(cuboid(x1, y1, z1, x2, y2, z2));
|
|
}
|
|
|
|
public Builder erase(double x1, double y1, double z1, double x2, double y2, double z2) {
|
|
this.shape =
|
|
VoxelShapes.join(shape, cuboid(x1, y1, z1, x2, y2, z2), IBooleanFunction.ONLY_FIRST);
|
|
return this;
|
|
}
|
|
|
|
public VoxelShape build() {
|
|
return shape;
|
|
}
|
|
|
|
public VoxelShaper build(BiFunction<VoxelShape, Direction, VoxelShaper> factory, Direction direction) {
|
|
return factory.apply(shape, direction);
|
|
}
|
|
|
|
public VoxelShaper build(BiFunction<VoxelShape, Axis, VoxelShaper> factory, Axis axis) {
|
|
return factory.apply(shape, axis);
|
|
}
|
|
|
|
public VoxelShaper forDirectional(Direction direction) {
|
|
return build(VoxelShaper::forDirectional, direction);
|
|
}
|
|
|
|
public VoxelShaper forAxis() {
|
|
return build(VoxelShaper::forAxis, Axis.Y);
|
|
}
|
|
|
|
public VoxelShaper forHorizontalAxis() {
|
|
return build(VoxelShaper::forHorizontalAxis, Axis.Z);
|
|
}
|
|
|
|
public VoxelShaper forHorizontal(Direction direction) {
|
|
return build(VoxelShaper::forHorizontal, direction);
|
|
}
|
|
|
|
public VoxelShaper forDirectional() {
|
|
return forDirectional(UP);
|
|
}
|
|
|
|
}
|
|
}
|