diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cc07fd8a..55a72a596 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/main/java/com/refinedmods/refinedstorage/block/CableBlock.java b/src/main/java/com/refinedmods/refinedstorage/block/CableBlock.java index d5de34fad..f838d393d 100644 --- a/src/main/java/com/refinedmods/refinedstorage/block/CableBlock.java +++ b/src/main/java/com/refinedmods/refinedstorage/block/CableBlock.java @@ -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)) { diff --git a/src/main/java/com/refinedmods/refinedstorage/block/ConstructorBlock.java b/src/main/java/com/refinedmods/refinedstorage/block/ConstructorBlock.java index 92bf39288..bccd3ccd0 100644 --- a/src/main/java/com/refinedmods/refinedstorage/block/ConstructorBlock.java +++ b/src/main/java/com/refinedmods/refinedstorage/block/ConstructorBlock.java @@ -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) { diff --git a/src/main/java/com/refinedmods/refinedstorage/block/DestructorBlock.java b/src/main/java/com/refinedmods/refinedstorage/block/DestructorBlock.java index 6f1c5d243..999111471 100644 --- a/src/main/java/com/refinedmods/refinedstorage/block/DestructorBlock.java +++ b/src/main/java/com/refinedmods/refinedstorage/block/DestructorBlock.java @@ -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) { diff --git a/src/main/java/com/refinedmods/refinedstorage/block/ExporterBlock.java b/src/main/java/com/refinedmods/refinedstorage/block/ExporterBlock.java index 85d04b412..b0a86230f 100644 --- a/src/main/java/com/refinedmods/refinedstorage/block/ExporterBlock.java +++ b/src/main/java/com/refinedmods/refinedstorage/block/ExporterBlock.java @@ -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) { diff --git a/src/main/java/com/refinedmods/refinedstorage/block/ExternalStorageBlock.java b/src/main/java/com/refinedmods/refinedstorage/block/ExternalStorageBlock.java index 8abb48f03..e203a2f41 100644 --- a/src/main/java/com/refinedmods/refinedstorage/block/ExternalStorageBlock.java +++ b/src/main/java/com/refinedmods/refinedstorage/block/ExternalStorageBlock.java @@ -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) { diff --git a/src/main/java/com/refinedmods/refinedstorage/block/ImporterBlock.java b/src/main/java/com/refinedmods/refinedstorage/block/ImporterBlock.java index 6c18ea2a7..02e5ca1c0 100644 --- a/src/main/java/com/refinedmods/refinedstorage/block/ImporterBlock.java +++ b/src/main/java/com/refinedmods/refinedstorage/block/ImporterBlock.java @@ -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) { diff --git a/src/main/java/com/refinedmods/refinedstorage/block/shape/ShapeCache.java b/src/main/java/com/refinedmods/refinedstorage/block/shape/ShapeCache.java new file mode 100644 index 000000000..ba9b50f98 --- /dev/null +++ b/src/main/java/com/refinedmods/refinedstorage/block/shape/ShapeCache.java @@ -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 CACHE = new HashMap<>(); + + public static VoxelShape getOrCreate(BlockState state, Function shapeFactory) { + return CACHE.computeIfAbsent(state, shapeFactory); + } +}