-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...anilla/src/main/java/com/ishland/c2me/opts/worldgen/vanilla/mixin/tlcache/MixinBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.ishland.c2me.opts.worldgen.vanilla.mixin.tlcache; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.util.function.BooleanBiFunction; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.util.shape.VoxelShapes; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
@Mixin(Block.class) | ||
public class MixinBlock { | ||
|
||
@Unique | ||
private static final ThreadLocal<Object2BooleanLinkedOpenHashMap<VoxelShape>> c2me$full_cube_shape_cache_tl = | ||
ThreadLocal.withInitial(() -> new Object2BooleanLinkedOpenHashMap<>(256, 0.25F) { | ||
@Override | ||
protected void rehash(int newN) { | ||
if (newN > n) { | ||
super.rehash(newN); | ||
} | ||
} | ||
}); | ||
|
||
/** | ||
* @author ishland | ||
* @reason use ThreadLocal cache | ||
*/ | ||
@Overwrite | ||
public static boolean isShapeFullCube(VoxelShape shape) { | ||
Object2BooleanLinkedOpenHashMap<VoxelShape> map = c2me$full_cube_shape_cache_tl.get(); | ||
if (map.containsKey(shape)) { | ||
return map.getAndMoveToFirst(shape); | ||
} else { | ||
boolean uncached = !VoxelShapes.matchesAnywhere(VoxelShapes.fullCube(), shape, BooleanBiFunction.NOT_SAME); | ||
if (map.size() >= 256) { | ||
map.removeLastBoolean(); | ||
} | ||
map.putAndMoveToFirst(shape, uncached); | ||
return uncached; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters