-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid running biome generator on client in singleplayer
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinChunk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.gtnewhorizons.angelica.mixins.early.sodium; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.biome.BiomeGenBase; | ||
import net.minecraft.world.biome.WorldChunkManager; | ||
import net.minecraft.world.chunk.Chunk; | ||
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.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Chunk.class) | ||
public abstract class MixinChunk { | ||
@Shadow | ||
public World worldObj; | ||
|
||
@Shadow | ||
private byte[] blockBiomeArray; | ||
|
||
@Shadow | ||
@Final | ||
public int xPosition, zPosition; | ||
|
||
@Inject(method = "fillChunk", at = @At("RETURN")) | ||
private void sodium$populateBiomes(CallbackInfo ci) { | ||
if(this.worldObj.isRemote && !Minecraft.getMinecraft().isSingleplayer()) { | ||
// We are in multiplayer, the server might not have sent all biomes to the client. | ||
// Populate them now while we're on the main thread. | ||
WorldChunkManager manager = this.worldObj.getWorldChunkManager(); | ||
for(int z = 0; z < 16; z++) { | ||
for(int x = 0; x < 16; x++) { | ||
int idx = (z << 4) + x; | ||
int biome = this.blockBiomeArray[idx] & 255; | ||
if(biome == 255) { | ||
BiomeGenBase generated = manager.getBiomeGenAt((this.xPosition << 4) + x, (this.zPosition << 4) + z); | ||
this.blockBiomeArray[idx] = (byte)(generated.biomeID & 255); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinChunkProviderServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.gtnewhorizons.angelica.mixins.early.sodium; | ||
|
||
import net.minecraft.world.biome.WorldChunkManager; | ||
import net.minecraft.world.chunk.Chunk; | ||
import net.minecraft.world.chunk.IChunkProvider; | ||
import net.minecraft.world.gen.ChunkProviderServer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(ChunkProviderServer.class) | ||
public class MixinChunkProviderServer { | ||
@Redirect(method = "originalLoadChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/IChunkProvider;provideChunk(II)Lnet/minecraft/world/chunk/Chunk;", remap = true), remap = false) | ||
private Chunk sodium$populateChunkWithBiomes(IChunkProvider instance, int chunkX, int chunkZ) { | ||
Chunk chunk = instance.provideChunk(chunkX, chunkZ); | ||
if(chunk != null) { | ||
WorldChunkManager manager = chunk.worldObj.getWorldChunkManager(); | ||
for(int z = 0; z < 16; z++) { | ||
for(int x = 0; x < 16; x++) { | ||
chunk.getBiomeGenForWorldCoords(x, z, manager); | ||
} | ||
} | ||
} | ||
return chunk; | ||
} | ||
} |