88import net .minecraft .world .level .biome .Biome ;
99import net .vulkanmod .render .chunk .build .biome .BiomeData ;
1010
11- import java .util .Arrays ;
12-
1311public class TintCache {
1412 private static final int SECTION_WIDTH = 16 ;
13+ private static final int BOUNDARY_WIDTH = 16 ;
14+ private static final int LAYER_COUNT = SECTION_WIDTH + (BOUNDARY_WIDTH * 2 );
1515
1616 private final Reference2ReferenceOpenHashMap <ColorResolver , Layer []> layers ;
1717
1818 private BiomeData biomeData ;
1919 private int blendRadius , totalWidth ;
2020 private int secX , secY , secZ ;
21- private int minX , minZ ;
22- private int maxX , maxZ ;
21+ private int minX , minY , minZ ;
22+ private int maxX , maxY , maxZ ;
2323
2424 private int dataSize ;
2525 private int [] temp ;
@@ -44,8 +44,11 @@ public void init(BiomeData biomeData, int blendRadius, int secX, int secY, int s
4444
4545 this .minX = (secX << 4 ) - blendRadius ;
4646 this .minZ = (secZ << 4 ) - blendRadius ;
47- this .maxX = (secX << 4 ) + 16 + blendRadius ;
48- this .maxZ = (secZ << 4 ) + 16 + blendRadius ;
47+ this .maxX = (secX << 4 ) + 15 + blendRadius ;
48+ this .maxZ = (secZ << 4 ) + 15 + blendRadius ;
49+
50+ this .minY = (secY << 4 ) - 2 ;
51+ this .maxY = this .minY + 15 + 4 ;
4952
5053 int size = totalWidth * totalWidth ;
5154
@@ -70,7 +73,7 @@ public void init(BiomeData biomeData, int blendRadius, int secX, int secY, int s
7073 }
7174
7275 public int getColor (BlockPos blockPos , ColorResolver colorResolver ) {
73- int relY = blockPos .getY () & 15 ;
76+ int relY = blockPos .getY () - this . minY ;
7477
7578 if (!this .layers .containsKey (colorResolver )) {
7679 addResolver (colorResolver );
@@ -84,9 +87,10 @@ public int getColor(BlockPos blockPos, ColorResolver colorResolver) {
8487
8588 int [] values = layer .getValues ();
8689
87- int relX = blockPos .getX () & 15 ;
88- int relZ = blockPos .getZ () & 15 ;
89- int idx = this .totalWidth * (relZ + this .blendRadius ) + (relX + this .blendRadius );
90+ int relX = blockPos .getX () - this .minX ;
91+ int relZ = blockPos .getZ () - this .minZ ;
92+
93+ int idx = this .totalWidth * (relZ ) + (relX );
9094 return values [idx ];
9195 }
9296
@@ -101,19 +105,22 @@ private void addResolver(ColorResolver colorResolver) {
101105 }
102106
103107 private Layer [] allocateLayers () {
104- Layer [] layers = new Layer [SECTION_WIDTH ];
108+ Layer [] layers = new Layer [LAYER_COUNT ];
109+
110+ for (int i = 0 ; i < LAYER_COUNT ; i ++) {
111+ layers [i ] = new Layer ();
112+ }
105113
106- Arrays .fill (layers , new Layer ());
107114 return layers ;
108115 }
109116
110117 private void calculateLayer (Layer layer , ColorResolver colorResolver , int y ) {
111- int absY = ( secY << 4 ) + y ;
118+ int absY = minY + y ;
112119
113120 int [] values = layer .values ;
114121
115- for (int absZ = minZ ; absZ < maxZ ; absZ ++) {
116- for (int absX = minX ; absX < maxX ; absX ++) {
122+ for (int absZ = minZ ; absZ <= maxZ ; absZ ++) {
123+ for (int absX = minX ; absX <= maxX ; absX ++) {
117124 Biome biome = this .biomeData .getBiome (absX , absY , absZ );
118125
119126 final int idx = (absX - minX ) + (absZ - minZ ) * totalWidth ;
0 commit comments