Avoid recreating arrays when computing block state cache

This commit is contained in:
embeddedt 2023-01-28 11:19:39 -05:00
parent 5c914deeb7
commit fa9a3bb890
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 26 additions and 1 deletions

View File

@ -39,6 +39,7 @@ public class ModernFixEarlyConfig {
this.addMixinRule("perf.nuke_empty_chunk_sections", true);
this.addMixinRule("perf.flatten_model_predicates", true);
this.addMixinRule("perf.deduplicate_location", true);
this.addMixinRule("perf.cache_blockstate_cache_arrays", true);
this.addMixinRule("safety", true);
this.addMixinRule("launch.transformer_cache", false);
this.addMixinRule("launch.class_search_cache", true);

View File

@ -0,0 +1,23 @@
package org.embeddedt.modernfix.mixin.perf.cache_blockstate_cache_arrays;
import net.minecraft.util.BlockVoxelShape;
import net.minecraft.util.Direction;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(targets = { "net/minecraft/block/AbstractBlock$AbstractBlockState$Cache" })
public class AbstractBlockStateCacheMixin {
private static final BlockVoxelShape[] MF_BLOCK_VOXEL_SHAPES = BlockVoxelShape.values();
private static final Direction.Axis[] DIRECTION_AXIS_VALUES = Direction.Axis.values();
@Redirect(method = "<init>(Lnet/minecraft/block/BlockState;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/BlockVoxelShape;values()[Lnet/minecraft/util/BlockVoxelShape;"))
private BlockVoxelShape[] getVoxelShapeValues() {
return MF_BLOCK_VOXEL_SHAPES;
}
@Redirect(method = "<init>(Lnet/minecraft/block/BlockState;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Direction$Axis;values()[Lnet/minecraft/util/Direction$Axis;"))
private Direction.Axis[] getDirectionAxisValues() {
return DIRECTION_AXIS_VALUES;
}
}

View File

@ -24,7 +24,8 @@
"perf.deduplicate_location.MixinResourceLocation",
"perf.sync_executor_sleep.SyncExecutorMixin",
"perf.compress_biome_container.MixinBiomeContainer",
"perf.nuke_empty_chunk_sections.MixinChunk"
"perf.nuke_empty_chunk_sections.MixinChunk",
"perf.cache_blockstate_cache_arrays.AbstractBlockStateCacheMixin"
],
"client": [
"feature.measure_time.MinecraftMixin",