55import java .util .function .IntPredicate ;
66import java .util .function .Predicate ;
77
8+ import org .jetbrains .annotations .Nullable ;
9+
10+ import me .pepperbell .continuity .api .client .ProcessingDataProvider ;
811import me .pepperbell .continuity .client .properties .BaseCTMProperties ;
912import me .pepperbell .continuity .client .util .biome .BiomeRetriever ;
1013import net .fabricmc .fabric .api .renderer .v1 .mesh .QuadView ;
@@ -35,7 +38,7 @@ public BaseProcessingPredicate(Set<Identifier> matchTilesSet, EnumSet<Direction>
3538 }
3639
3740 @ Override
38- public boolean shouldProcessQuad (QuadView quad , Sprite sprite , BlockRenderView blockView , BlockState state , BlockPos pos ) {
41+ public boolean shouldProcessQuad (QuadView quad , Sprite sprite , BlockRenderView blockView , BlockState state , BlockPos pos , ProcessingDataProvider dataProvider ) {
3942 if (matchTilesSet != null ) {
4043 if (!matchTilesSet .contains (sprite .getId ())) {
4144 return false ;
@@ -61,26 +64,14 @@ public boolean shouldProcessQuad(QuadView quad, Sprite sprite, BlockRenderView b
6164 }
6265 }
6366 if (biomePredicate != null ) {
64- Biome biome = BiomeRetriever .getBiome (blockView , pos );
65- if (biome != null ) {
66- if (!biomePredicate .test (biome )) {
67- return false ;
68- }
69- } else {
67+ Biome biome = dataProvider .getData (ProcessingDataKeys .BIOME_CACHE_KEY ).get (blockView , pos );
68+ if (biome == null || !biomePredicate .test (biome )) {
7069 return false ;
7170 }
7271 }
7372 if (blockEntityNamePredicate != null ) {
74- BlockEntity blockEntity = blockView .getBlockEntity (pos );
75- if (blockEntity instanceof Nameable nameable ) {
76- if (nameable .hasCustomName ()) {
77- if (!blockEntityNamePredicate .test (nameable .getCustomName ().asString ())) {
78- return false ;
79- }
80- } else {
81- return false ;
82- }
83- } else {
73+ String blockEntityName = dataProvider .getData (ProcessingDataKeys .BLOCK_ENTITY_NAME_CACHE_KEY ).get (blockView , pos );
74+ if (blockEntityName == null || !blockEntityNamePredicate .test (blockEntityName )) {
8475 return false ;
8576 }
8677 }
@@ -90,4 +81,49 @@ public boolean shouldProcessQuad(QuadView quad, Sprite sprite, BlockRenderView b
9081 public static BaseProcessingPredicate fromProperties (BaseCTMProperties properties ) {
9182 return new BaseProcessingPredicate (properties .getMatchTilesSet (), properties .getFaces (), properties .getBiomePredicate (), properties .getHeightPredicate (), properties .getBlockEntityNamePredicate ());
9283 }
84+
85+ public static class BiomeCache {
86+ protected Biome biome ;
87+ protected boolean invalid = true ;
88+
89+ @ Nullable
90+ public Biome get (BlockRenderView blockView , BlockPos pos ) {
91+ if (invalid ) {
92+ biome = BiomeRetriever .getBiome (blockView , pos );
93+ invalid = false ;
94+ }
95+ return biome ;
96+ }
97+
98+ public void reset () {
99+ invalid = true ;
100+ }
101+ }
102+
103+ public static class BlockEntityNameCache {
104+ protected String blockEntityName ;
105+ protected boolean invalid = true ;
106+
107+ @ Nullable
108+ public String get (BlockRenderView blockView , BlockPos pos ) {
109+ if (invalid ) {
110+ BlockEntity blockEntity = blockView .getBlockEntity (pos );
111+ if (blockEntity instanceof Nameable nameable ) {
112+ if (nameable .hasCustomName ()) {
113+ blockEntityName = nameable .getCustomName ().asString ();
114+ } else {
115+ blockEntityName = null ;
116+ }
117+ } else {
118+ blockEntityName = null ;
119+ }
120+ invalid = false ;
121+ }
122+ return blockEntityName ;
123+ }
124+
125+ public void reset () {
126+ invalid = true ;
127+ }
128+ }
93129}
0 commit comments