Fixed performance issue where shapes of cable blocks were constantly being recalculated. Fixes #2599

This commit is contained in:
raoulvdberge
2020-07-11 16:12:13 +02:00
parent 290e9bd59c
commit a9bfe70587
8 changed files with 52 additions and 15 deletions

View File

@@ -8,6 +8,7 @@
- Fixed bug where autocrafting tasks started on the same tick make the wrong assumption about available items and fluids (Darkere)
- Fixed bug where the "To craft" amount in the Crafting Preview window is wrong (raoulvdberge)
- Fixed bug where non-pattern items are able to be inserted into the Crafter Manager (Darkere)
- Fixed performance issue where shapes of cable blocks were constantly being recalculated (raoulvdberge)
- Drastically improved shift clicking performance in Crafting Grid (Darkere)
- Removed autocrafting engine version from crafting preview screen (raoulvdberge)

View File

@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.block;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.block.shape.ShapeCache;
import com.refinedmods.refinedstorage.capability.NetworkNodeProxyCapability;
import com.refinedmods.refinedstorage.tile.CableTile;
import com.refinedmods.refinedstorage.util.BlockUtils;
@@ -70,6 +71,10 @@ public class CableBlock extends NetworkNodeBlock implements IWaterLoggable {
@Override
@SuppressWarnings("deprecation")
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
return ShapeCache.getOrCreate(state, CableBlock::getCableShape);
}
protected static VoxelShape getCableShape(BlockState state) {
VoxelShape shape = SHAPE_CORE;
if (state.get(NORTH)) {

View File

@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.block;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.block.shape.ShapeCache;
import com.refinedmods.refinedstorage.container.ConstructorContainer;
import com.refinedmods.refinedstorage.container.factory.PositionalTileContainerProvider;
import com.refinedmods.refinedstorage.tile.ConstructorTile;
@@ -53,11 +54,13 @@ public class ConstructorBlock extends CableBlock {
@Override
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
VoxelShape shape = super.getShape(state, world, pos, ctx);
return ShapeCache.getOrCreate(state, s -> {
VoxelShape shape = getCableShape(s);
shape = VoxelShapes.or(shape, getHeadShape(state));
shape = VoxelShapes.or(shape, getHeadShape(s));
return shape;
return shape;
});
}
private VoxelShape getHeadShape(BlockState state) {

View File

@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.block;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.block.shape.ShapeCache;
import com.refinedmods.refinedstorage.container.DestructorContainer;
import com.refinedmods.refinedstorage.container.factory.PositionalTileContainerProvider;
import com.refinedmods.refinedstorage.tile.DestructorTile;
@@ -53,11 +54,13 @@ public class DestructorBlock extends CableBlock {
@Override
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
VoxelShape shape = super.getShape(state, world, pos, ctx);
return ShapeCache.getOrCreate(state, s -> {
VoxelShape shape = getCableShape(s);
shape = VoxelShapes.or(shape, getHeadShape(state));
shape = VoxelShapes.or(shape, getHeadShape(s));
return shape;
return shape;
});
}
private VoxelShape getHeadShape(BlockState state) {

View File

@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.block;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.block.shape.ShapeCache;
import com.refinedmods.refinedstorage.container.ExporterContainer;
import com.refinedmods.refinedstorage.container.factory.PositionalTileContainerProvider;
import com.refinedmods.refinedstorage.tile.ExporterTile;
@@ -70,11 +71,13 @@ public class ExporterBlock extends CableBlock {
@Override
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
VoxelShape shape = super.getShape(state, world, pos, ctx);
return ShapeCache.getOrCreate(state, s -> {
VoxelShape shape = getCableShape(s);
shape = VoxelShapes.or(shape, getLineShape(state));
shape = VoxelShapes.or(shape, getLineShape(s));
return shape;
return shape;
});
}
private VoxelShape getLineShape(BlockState state) {

View File

@@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.api.network.node.INetworkNode;
import com.refinedmods.refinedstorage.api.storage.cache.InvalidateCause;
import com.refinedmods.refinedstorage.apiimpl.network.node.ExternalStorageNetworkNode;
import com.refinedmods.refinedstorage.block.shape.ShapeCache;
import com.refinedmods.refinedstorage.container.ExternalStorageContainer;
import com.refinedmods.refinedstorage.container.factory.PositionalTileContainerProvider;
import com.refinedmods.refinedstorage.tile.ExternalStorageTile;
@@ -51,11 +52,13 @@ public class ExternalStorageBlock extends CableBlock {
@Override
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
VoxelShape shape = super.getShape(state, world, pos, ctx);
return ShapeCache.getOrCreate(state, s -> {
VoxelShape shape = getCableShape(s);
shape = VoxelShapes.or(shape, getHeadShape(state));
shape = VoxelShapes.or(shape, getHeadShape(s));
return shape;
return shape;
});
}
private VoxelShape getHeadShape(BlockState state) {

View File

@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.block;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.block.shape.ShapeCache;
import com.refinedmods.refinedstorage.container.ImporterContainer;
import com.refinedmods.refinedstorage.container.factory.PositionalTileContainerProvider;
import com.refinedmods.refinedstorage.tile.ImporterTile;
@@ -70,11 +71,13 @@ public class ImporterBlock extends CableBlock {
@Override
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
VoxelShape shape = super.getShape(state, world, pos, ctx);
return ShapeCache.getOrCreate(state, s -> {
VoxelShape shape = getCableShape(s);
shape = VoxelShapes.or(shape, getLineShape(state));
shape = VoxelShapes.or(shape, getLineShape(s));
return shape;
return shape;
});
}
private VoxelShape getLineShape(BlockState state) {

View File

@@ -0,0 +1,16 @@
package com.refinedmods.refinedstorage.block.shape;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.shapes.VoxelShape;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
public class ShapeCache {
private static final Map<BlockState, VoxelShape> CACHE = new HashMap<>();
public static VoxelShape getOrCreate(BlockState state, Function<BlockState, VoxelShape> shapeFactory) {
return CACHE.computeIfAbsent(state, shapeFactory);
}
}