34
34
import io .github .opencubicchunks .cubicchunks .api .world .ICube ;
35
35
import io .github .opencubicchunks .cubicchunks .api .world .ICubicWorld ;
36
36
import io .github .opencubicchunks .cubicchunks .api .world .IHeightMap ;
37
+ import io .github .opencubicchunks .cubicchunks .api .world .IMinMaxHeight ;
37
38
import io .github .opencubicchunks .cubicchunks .core .CubicChunksConfig ;
38
39
import io .github .opencubicchunks .cubicchunks .core .asm .mixin .ICubicWorldInternal ;
39
40
import io .github .opencubicchunks .cubicchunks .core .world .ClientHeightMap ;
@@ -148,7 +149,7 @@ public <T extends World & ICubicWorldInternal> T getWorld() {
148
149
@ Unique @ Nullable
149
150
private ExtendedBlockStorage getEBS_CubicChunks (int index ) {
150
151
if (!isColumn ) {
151
- return storageArrays [index ];
152
+ return storageArrays [index - Coords . blockToCube ( getWorld (). getMinHeight ()) ];
152
153
}
153
154
if (cachedCube != null && cachedCube .getY () == index ) {
154
155
return cachedCube .getStorage ();
@@ -163,7 +164,7 @@ private ExtendedBlockStorage getEBS_CubicChunks(int index) {
163
164
// setEBS is unlikely to be used extremely frequently, no caching
164
165
@ Unique private void setEBS_CubicChunks (int index , ExtendedBlockStorage ebs ) {
165
166
if (!isColumn ) {
166
- storageArrays [index ] = ebs ;
167
+ storageArrays [index - Coords . blockToCube ( getWorld (). getMinHeight ()) ] = ebs ;
167
168
return ;
168
169
}
169
170
if (index >= 0 && index < 16 ) {
@@ -221,6 +222,31 @@ private void cubicChunkColumn_construct(World world, int x, int z, CallbackInfo
221
222
Arrays .fill (getBiomeArray (), (byte ) -1 );
222
223
}
223
224
225
+ @ ModifyConstant (method = "<init>(Lnet/minecraft/world/World;II)V" , constant = @ Constant (intValue = 16 ))
226
+ private int modifySectionArrayLength (int sixteen , World worldIn , int x , int z ) {
227
+ IMinMaxHeight y = (IMinMaxHeight ) worldIn ;
228
+ return Coords .blockToCube (y .getMaxHeight ()) - Coords .blockToCube (y .getMinHeight ()) + 1 ;
229
+ }
230
+
231
+ @ Redirect (method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/ChunkPrimer;II)V" ,
232
+ at = @ At (
233
+ value = "FIELD" ,
234
+ args = "array=get" ,
235
+ target = "Lnet/minecraft/world/chunk/Chunk;storageArrays:[Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;"
236
+ ))
237
+ private ExtendedBlockStorage init_getStorage (ExtendedBlockStorage [] ebs , int y ) {
238
+ return ebs [y - Coords .blockToCube (((IMinMaxHeight ) world ).getMinHeight ())];
239
+ }
240
+
241
+ @ Redirect (method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/ChunkPrimer;II)V" ,
242
+ at = @ At (
243
+ value = "FIELD" ,
244
+ args = "array=set" ,
245
+ target = "Lnet/minecraft/world/chunk/Chunk;storageArrays:[Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;"
246
+ ))
247
+ private void getBlockState_getMaxHeight (ExtendedBlockStorage [] ebs , int y , ExtendedBlockStorage val ) {
248
+ ebs [y - Coords .blockToCube (((IMinMaxHeight ) world ).getMinHeight ())] = val ;
249
+ }
224
250
@ ModifyConstant (method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/ChunkPrimer;II)V" ,
225
251
constant = @ Constant (intValue = 16 , ordinal = 0 ), require = 1 )
226
252
private int getInitChunkLoopEnd (int _16 , World world , ChunkPrimer primer , int x , int z ) {
@@ -300,6 +326,17 @@ private void generateSkylightMap_CubicChunks_Replace(CallbackInfo cbi) {
300
326
}
301
327
}
302
328
329
+
330
+ @ Nullable
331
+ @ Redirect (method = "generateSkylightMap" , at = @ At (
332
+ value = "FIELD" ,
333
+ target = "Lnet/minecraft/world/chunk/Chunk;storageArrays:[Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;" ,
334
+ args = "array=get"
335
+ ))
336
+ private ExtendedBlockStorage generateSkylightMapRedirectEBSAccess (ExtendedBlockStorage [] array , int index ) {
337
+ return getEBS_CubicChunks (index );
338
+ }
339
+
303
340
// ==============================================
304
341
// propagateSkylightOcclusion
305
342
// ==============================================
@@ -402,7 +439,7 @@ private boolean getBlockLightOpacity_isChunkLoadedCubeRedirect(Chunk chunk, int
402
439
constant = @ Constant (expandZeroConditions = Constant .Condition .GREATER_THAN_OR_EQUAL_TO_ZERO ),
403
440
require = 1 )
404
441
private int getBlockState_getMinHeight (int zero ) {
405
- return isColumn ? Integer .MIN_VALUE : 0 ;
442
+ return isColumn ? Integer .MIN_VALUE : getWorld (). getMinHeight (); // this one is in block coords, max is in cube coords. Mojang logic.
406
443
}
407
444
408
445
@ Redirect (method = "getBlockState(III)Lnet/minecraft/block/state/IBlockState;" ,
@@ -412,7 +449,7 @@ private int getBlockState_getMinHeight(int zero) {
412
449
target = "Lnet/minecraft/world/chunk/Chunk;storageArrays:[Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;"
413
450
))
414
451
private int getBlockState_getMaxHeight (ExtendedBlockStorage [] ebs ) {
415
- return isColumn ? Integer .MAX_VALUE : ebs .length ;
452
+ return isColumn ? Integer .MAX_VALUE : ( ebs .length - Coords . blockToCube ( getWorld (). getMinHeight ())) ;
416
453
}
417
454
418
455
@ Redirect (method = "getBlockState(III)Lnet/minecraft/block/state/IBlockState;" ,
@@ -421,7 +458,7 @@ private int getBlockState_getMaxHeight(ExtendedBlockStorage[] ebs) {
421
458
args = "array=get" ,
422
459
target = "Lnet/minecraft/world/chunk/Chunk;storageArrays:[Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;"
423
460
))
424
- private ExtendedBlockStorage getBlockState_getMaxHeight (ExtendedBlockStorage [] ebs , int y ) {
461
+ private ExtendedBlockStorage getBlockState_getStorage (ExtendedBlockStorage [] ebs , int y ) {
425
462
return getEBS_CubicChunks (y );
426
463
}
427
464
@@ -592,7 +629,7 @@ private int addEntity_getMinY(int zero) {
592
629
),
593
630
require = 2 )
594
631
private int addEntity_getMaxHeight (ClassInheritanceMultiMap <?>[] entityLists ) {
595
- return isColumn ? blockToCube (getWorld ().getMaxHeight ()) : entityLists .length ;
632
+ return isColumn ? blockToCube (getWorld ().getMaxHeight ()) : ( entityLists .length - Coords . blockToCube ( getWorld (). getMinHeight ())) ;
596
633
}
597
634
598
635
@ Redirect (method = "addEntity" ,
@@ -604,7 +641,7 @@ private int addEntity_getMaxHeight(ClassInheritanceMultiMap<?>[] entityLists) {
604
641
require = 1 )
605
642
private ClassInheritanceMultiMap <?> addEntity_getEntityList (ClassInheritanceMultiMap <?>[] entityLists , int idx , Entity entity ) {
606
643
if (!isColumn ) {
607
- return entityLists [idx ];
644
+ return entityLists [idx - Coords . blockToCube ( getWorld (). getMinHeight ()) ];
608
645
} else if (cachedCube != null && cachedCube .getY () == idx ) {
609
646
cachedCube .getEntityContainer ().addEntity (entity );
610
647
return null ;
@@ -652,7 +689,7 @@ private int removeEntityAtIndex_getMinY(int zero) {
652
689
),
653
690
require = 2 )
654
691
private int removeEntityAtIndex_getMaxHeight (ClassInheritanceMultiMap <?>[] entityLists ) {
655
- return isColumn ? blockToCube (getWorld ().getMaxHeight ()) : entityLists .length ;
692
+ return isColumn ? blockToCube (getWorld ().getMaxHeight ()) : ( entityLists .length - Coords . blockToCube ( getWorld (). getMinHeight ())) ;
656
693
}
657
694
658
695
@ Redirect (method = "removeEntityAtIndex" ,
@@ -665,7 +702,7 @@ private int removeEntityAtIndex_getMaxHeight(ClassInheritanceMultiMap<?>[] entit
665
702
private ClassInheritanceMultiMap <?> removeEntityAtIndex_getEntityList (ClassInheritanceMultiMap <?>[] entityLists , int idx , Entity entity ,
666
703
int index ) {
667
704
if (!isColumn ) {
668
- return entityLists [idx ];
705
+ return entityLists [idx - Coords . blockToCube ( getWorld (). getMinHeight ()) ];
669
706
} else if (cachedCube != null && cachedCube .getY () == idx ) {
670
707
cachedCube .getEntityContainer ().remove (entity );
671
708
return null ;
0 commit comments