Add multipart container hasSolidTopSurface implementation

This commit is contained in:
Shadowfacts 2019-01-05 18:14:29 -05:00
parent e2db11e181
commit b6813ad14d
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 37 additions and 0 deletions

View File

@ -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);

View File

@ -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;
}
}