11package org .dimdev .jeid .mixin .core ;
22
3+ import net .minecraft .init .Biomes ;
34import net .minecraft .util .math .BlockPos ;
5+ import net .minecraft .world .World ;
46import net .minecraft .world .biome .Biome ;
57import net .minecraft .world .biome .BiomeProvider ;
68import net .minecraft .world .chunk .Chunk ;
79import org .dimdev .jeid .INewChunk ;
810import org .dimdev .jeid .JEID ;
9- import org .dimdev . jeid . Utils ;
11+ import org .spongepowered . asm . mixin . Final ;
1012import org .spongepowered .asm .mixin .Mixin ;
1113import org .spongepowered .asm .mixin .Overwrite ;
12- import org .spongepowered .asm .mixin .injection .*;
13- import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
14- import org .spongepowered .asm .mixin .injection .callback .LocalCapture ;
14+ import org .spongepowered .asm .mixin .Shadow ;
1515
1616import java .util .Arrays ;
1717
1818@ Mixin (Chunk .class )
1919public class MixinChunk implements INewChunk {
20+
21+
22+ @ Shadow @ Final private World world ;
23+
2024 private static final byte errorBiomeID = (byte ) Biome .REGISTRY .getIDForObject (JEID .errorBiome );
2125 private final int [] intBiomeArray = generateIntBiomeArray ();
2226
@@ -36,25 +40,45 @@ public void setIntBiomeArray(int[] intBiomeArray) {
3640 System .arraycopy (intBiomeArray , 0 , this .intBiomeArray , 0 , this .intBiomeArray .length );
3741 }
3842
43+ /**
44+ * @author Unknown
45+ */
3946 @ Overwrite
4047 public byte [] getBiomeArray () {
4148 byte [] arr = new byte [256 ];
4249 Arrays .fill (arr , errorBiomeID );
4350 return arr ;
4451 }
4552
46- @ Redirect (method = "getBiome" , at = @ At (value = "FIELD" , target = "Lnet/minecraft/world/chunk/Chunk;blockBiomeArray:[B" , args = "array=get" ))
47- private int getIntBiomeIdFromArray (byte [] array , int index ) {
48- return this .intBiomeArray [index ];
49- }
53+ /**
54+ * @author Clienthax
55+ * @reason No way to modify locals in the manner we need currently..
56+ */
57+ @ Overwrite
58+ public Biome getBiome (BlockPos pos , BiomeProvider provider )
59+ {
60+ int i = pos .getX () & 15 ;
61+ int j = pos .getZ () & 15 ;
62+ //JEID START
63+ int k = this .intBiomeArray [j << 4 | i ];
64+ //JEID END
5065
51- @ Inject (method = "getBiome" , at = @ At (value = "FIELD" , target = "Lnet/minecraft/world/chunk/Chunk;blockBiomeArray:[B" , args = "array=set" ), locals = LocalCapture .CAPTURE_FAILHARD )
52- private void setIntBiomeIdInArray (BlockPos pos , BiomeProvider provider , CallbackInfoReturnable <Biome > cir , int i , int j , int k , Biome biome ) {
53- this .intBiomeArray [j << 4 | i ] = k ;
54- }
66+ if (k == 255 )
67+ {
68+ // Forge: checking for client ensures that biomes are only generated on integrated server
69+ // in singleplayer. Generating biomes on the client may corrupt the biome ID arrays on
70+ // the server while they are being generated because IntCache can't be thread safe,
71+ // so client and server may end up filling the same array.
72+ // This is not necessary in 1.13 and newer versions.
73+ Biome biome = world .isRemote ? Biomes .PLAINS : provider .getBiome (pos , Biomes .PLAINS );
74+ k = Biome .getIdForBiome (biome );
75+ //JEID START
76+ this .intBiomeArray [j << 4 | i ] = k ;
77+ //JEID END
78+ }
5579
56- @ ModifyConstant (method = "getBiome" , constant = @ Constant (intValue = 0xFF ))
57- private int getBiomeBitmask (int oldValue ) {
58- return 0xFFFFFFFF ;
80+ Biome biome1 = Biome .getBiome (k );
81+ return biome1 == null ? Biomes .PLAINS : biome1 ;
5982 }
83+
6084}
0 commit comments