Skip to content

Commit

Permalink
Fix mod incompatibility with mods that redirect generateChunk.
Browse files Browse the repository at this point in the history
Since NotEnoughIDs isn't changing generateChunk and, instead, is only
changing the biome array, we can safely inject afterwards.

Addresses incompatibility with SpongeForge.

Signed-off-by: Chris Sanders <[email protected]>
  • Loading branch information
Zidane authored and Runemoro committed Aug 4, 2019
1 parent c87fb63 commit 7b36529
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.gen.IChunkGenerator;
import org.dimdev.jeid.INewChunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(ChunkProviderServer.class)
public class MixinChunkProviderServer {
@Shadow @Final public WorldServer world;
private Biome[] reusableBiomeList = new Biome[256];

/** @reason Return an empty biome byte array if the chunk is using an int biome array. **/
@Redirect(method = "provideChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/IChunkGenerator;generateChunk(II)Lnet/minecraft/world/chunk/Chunk;"))
private Chunk generateChunk(IChunkGenerator generator, int x, int z) {
Chunk chunk = generator.generateChunk(x, z);
@Inject(method = "provideChunk", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/gen/IChunkGenerator;generateChunk(II)Lnet/minecraft/world/chunk/Chunk;"), locals = LocalCapture.CAPTURE_FAILHARD)
private void initializeBiomeArray(int x, int z, CallbackInfoReturnable<Chunk> cir, Chunk chunk) {
Biome[] biomes = world.getBiomeProvider().getBiomes(reusableBiomeList, x * 16, z * 16, 16, 16);

INewChunk newChunk = (INewChunk) chunk;
int[] intBiomeArray = newChunk.getIntBiomeArray();
for (int i = 0; i < intBiomeArray.length; ++i) {
intBiomeArray[i] = Biome.getIdForBiome(biomes[i]);
}
return chunk;
}
}

0 comments on commit 7b36529

Please sign in to comment.