Add multipart container hasSolidTopSurface implementation
This commit is contained in:
parent
e2db11e181
commit
b6813ad14d
|
@ -15,6 +15,7 @@ import net.shadowfacts.simplemultipart.client.util.RenderStateProvider;
|
|||
import net.shadowfacts.simplemultipart.util.MultipartHelper;
|
||||
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
|
||||
import net.shadowfacts.simplemultipart.multipart.MultipartView;
|
||||
import net.shadowfacts.simplemultipart.util.ShapeUtils;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -69,6 +70,21 @@ public abstract class AbstractContainerBlock extends Block implements BlockEntit
|
|||
return shape == null ? VoxelShapes.empty() : shape;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean hasSolidTopSurface(BlockState state, BlockView world, BlockPos pos) {
|
||||
MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return container.getParts().stream()
|
||||
.anyMatch(view -> {
|
||||
VoxelShape shape = view.getState().getBoundingShape(view);
|
||||
return ShapeUtils.hasSolidSide(shape, Direction.UP);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract AbstractContainerBlockEntity createBlockEntity(BlockView world);
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package net.shadowfacts.simplemultipart.util;
|
||||
|
||||
import net.minecraft.util.BooleanBiFunction;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.DoubleFunction;
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
|
@ -15,4 +19,21 @@ public class ShapeUtils {
|
|||
return !overlap.isEmpty();
|
||||
}
|
||||
|
||||
public static boolean hasSolidSide(VoxelShape shape, Direction side) {
|
||||
BiFunction<VoxelShape, Direction.Axis, Double> getter = side.getDirection() == Direction.AxisDirection.NEGATIVE ? VoxelShape::getMinimum : VoxelShape::getMaximum;
|
||||
if (getter.apply(shape, side.getAxis()) < 1) {
|
||||
return false;
|
||||
}
|
||||
for (Direction.Axis axis : Direction.Axis.values()) {
|
||||
if (axis == side.getAxis()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (shape.getMinimum(axis) > 0 || shape.getMaximum(axis) < 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue