Merge fixes.

This commit is contained in:
Sebastian Hartte
2020-09-09 02:23:14 +02:00
parent fcbebd4ffc
commit 17648633fe
9 changed files with 151 additions and 65 deletions
+16 -17
View File
@@ -18,21 +18,20 @@
package appeng.parts;
import java.util.List;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.minecraft.util.function.BooleanBiFunction;
import net.minecraft.util.math.Box;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import java.util.List;
/**
* While creation of a {@link VoxelShape} with
* {@link VoxelShapes#create(AxisAlignedBB)} is fast enough, combining voxel
* shapes with {@link VoxelShapes#or(VoxelShape, VoxelShape)} or any other
* While creation of a {@link net.minecraft.util.shape.VoxelShape} with
* {@link net.minecraft.util.shape.VoxelShapes#cuboid(Box)} is fast enough, combining voxel
* shapes with {@link net.minecraft.util.shape.VoxelShapes#union(VoxelShape, VoxelShape)} or any other
* combination method, as well as {@link VoxelShape#simplify()} are <b>extremely
* slow</b>. For example: Creating a VoxelShape for a list of 5 bounding boxes
* 10,000 times takes about 1.7 seconds.
@@ -48,11 +47,11 @@ final class VoxelShapeCache {
// are iterated over in a fixed order, meaning the order of bounding boxes
// should
// be the same for a same set of parts.
private static final LoadingCache<List<AxisAlignedBB>, VoxelShape> CACHE = CacheBuilder.newBuilder()//
private static final LoadingCache<List<Box>, VoxelShape> CACHE = CacheBuilder.newBuilder()//
.maximumSize(10000L)//
.build(new CacheLoader<List<AxisAlignedBB>, VoxelShape>() {
.build(new CacheLoader<List<Box>, VoxelShape>() {
@Override
public VoxelShape load(List<AxisAlignedBB> key) {
public VoxelShape load(List<Box> key) {
return create(key);
}
});
@@ -60,20 +59,20 @@ final class VoxelShapeCache {
private VoxelShapeCache() {
}
public static VoxelShape get(List<AxisAlignedBB> boxes) {
public static VoxelShape get(List<Box> boxes) {
return CACHE.getUnchecked(boxes);
}
private static VoxelShape create(List<AxisAlignedBB> boxes) {
private static VoxelShape create(List<Box> boxes) {
if (boxes.isEmpty()) {
return VoxelShapes.empty();
}
int i = 0;
VoxelShape shape = VoxelShapes.create(boxes.get(i));
VoxelShape shape = VoxelShapes.cuboid(boxes.get(i));
for (; i < boxes.size(); i++) {
AxisAlignedBB box = boxes.get(i);
shape = VoxelShapes.combine(shape, VoxelShapes.create(box), IBooleanFunction.OR);
Box box = boxes.get(i);
shape = VoxelShapes.combine(shape, VoxelShapes.cuboid(box), BooleanBiFunction.OR);
}
return shape.simplify();
}