chunk provider logic unification

This commit is contained in:
FalsePattern committed 2022-07-10 23:34:52 +02:00
1 parent 15803fceff
commit 3b85cf7db5
8 files changed
+117 -217

No files matched your search

@@ -0,0 +1,31 @@
package com.falsepattern.endlessids.mixin.helpers;
import gnu.trove.function.TIntFunction;
import lombok.val;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import java.util.function.IntFunction;
import static com.falsepattern.endlessids.EndlessIDs.BIOME_ARRAY_PLACEHOLDER;
public class BiomePatchHelper {
public static byte[] getBiomeArrayTweaked(Chunk chunk, IntFunction<BiomeGenBase> biomesForGeneration) {
val chunkBiomes = ((IChunkMixin)chunk).getBiomeShortArray();
for(int i = 0; i < chunkBiomes.length; ++i) {
chunkBiomes[i] = (short) biomesForGeneration.apply(i).biomeID;
}
return BIOME_ARRAY_PLACEHOLDER;
}
public static byte[] getBiomeArrayTweaked(Chunk chunk, BiomeGenBase[] biomesForGeneration) {
val chunkBiomes = ((IChunkMixin)chunk).getBiomeShortArray();
for(int i = 0; i < chunkBiomes.length; ++i) {
chunkBiomes[i] = (short) biomesForGeneration[i].biomeID;
}
return BIOME_ARRAY_PLACEHOLDER;
}
}
@@ -1,13 +1,13 @@
package com.falsepattern.endlessids.mixin.mixins.common.atg;
import com.falsepattern.endlessids.mixin.helpers.BiomePatchHelper;
import com.falsepattern.endlessids.mixin.helpers.IChunkMixin;
import lombok.val;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import ttftcuts.atg.ATGChunkProvider;
import net.minecraft.block.Block;
@@ -20,21 +20,13 @@ public abstract class ATGChunkProviderMixin {
@Shadow
private BiomeGenBase[] biomesForGeneration;
@Inject(method = "provideChunk",
at = @At(value = "INVOKE",
@Redirect(method = "provideChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B",
remap = true,
shift = At.Shift.BEFORE),
cancellable = true,
remap = true,
locals = LocalCapture.CAPTURE_FAILHARD,
require = 1)
private void hijackChunkBiomeSetup(int chunkX, int chunkY, CallbackInfoReturnable<Chunk> cir, Block[] data, byte[] abyte, Chunk chunk) {
val chunkBiomes = ((IChunkMixin) chunk).getBiomeShortArray();
for (int i = 0; i < chunkBiomes.length; i++) {
chunkBiomes[i] = (short) biomesForGeneration[i].biomeID;
}
chunk.generateSkylightMap();
cir.setReturnValue(chunk);
remap = true),
remap = true,
require = 1)
private byte[] setBiomesTweaked(Chunk chunk) {
return BiomePatchHelper.getBiomeArrayTweaked(chunk, biomesForGeneration);
}
}
@@ -1,5 +1,6 @@
package com.falsepattern.endlessids.mixin.mixins.common.rtg;
import com.falsepattern.endlessids.mixin.helpers.BiomePatchHelper;
import com.falsepattern.endlessids.mixin.helpers.IChunkMixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -25,13 +26,8 @@ public abstract class ChunkProviderRTGMixin {
remap = true),
remap = true,
require = 1)
private byte[] redictBiomeArrayFillLogic(Chunk chunk) {
short[] biomes = ((IChunkMixin) chunk).getBiomeShortArray();
for (int i = 0; i < biomes.length; ++i) {
biomes[i] = (short) baseBiomesList[xyinverted[i]].biomeID;
}
return new byte[0];
private byte[] setBiomesTweaked(Chunk chunk) {
return BiomePatchHelper.getBiomeArrayTweaked(chunk, (i) -> baseBiomesList[xyinverted[i]]);
}
@Redirect(method = "provideChunk",
@@ -1,7 +1,6 @@
package com.falsepattern.endlessids.mixin.mixins.common.tf;
import com.falsepattern.endlessids.mixin.helpers.IChunkMixin;
import lombok.val;
import com.falsepattern.endlessids.mixin.helpers.BiomePatchHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -11,8 +10,6 @@ import twilightforest.world.ChunkProviderTwilightForest;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import static com.falsepattern.endlessids.EndlessIDs.BIOME_ARRAY_PLACEHOLDER;
@Mixin(value = ChunkProviderTwilightForest.class,
remap = false)
public abstract class ChunkProviderTwilightForestMixin {
@@ -20,15 +17,11 @@ public abstract class ChunkProviderTwilightForestMixin {
@Redirect(method = "provideChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B"),
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B",
remap = true),
remap = true,
require = 1)
private byte[] bypassBiomeProcessing(Chunk chunk) {
val chunkBiomes = ((IChunkMixin)chunk).getBiomeShortArray();
for(int i = 0; i < chunkBiomes.length; ++i) {
chunkBiomes[i] = (short) this.biomesForGeneration[i].biomeID;
}
return BIOME_ARRAY_PLACEHOLDER;
private byte[] setBiomesTweaked(Chunk chunk) {
return BiomePatchHelper.getBiomeArrayTweaked(chunk, biomesForGeneration);
}
}
@@ -1,9 +1,12 @@
package com.falsepattern.endlessids.mixin.mixins.common.vanilla.worldgen;
import com.falsepattern.endlessids.mixin.helpers.BiomePatchHelper;
import com.falsepattern.endlessids.mixin.helpers.IChunkMixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import net.minecraft.block.Block;
import net.minecraft.world.World;
@@ -15,44 +18,14 @@ import java.util.Random;
@Mixin(ChunkProviderEnd.class)
public abstract class ChunkProviderEndMixin {
@Shadow
private Random endRNG;
@Shadow
private BiomeGenBase[] biomesForGeneration;
@Shadow
private World endWorld;
@Shadow
public abstract void func_147420_a(int p_147420_1_, int p_147420_2_, Block[] p_147420_3_, BiomeGenBase[] p_147420_4_);
@Shadow(remap = false)
public abstract void replaceBiomeBlocks(int p_147421_1_, int p_147421_2_, Block[] p_147421_3_, BiomeGenBase[] p_147421_4_, byte[] meta);
/**
* @author FalsePattern
* @reason Direct port from decompiled code
*/
@Overwrite
public Chunk provideChunk(int x, int z) {
this.endRNG.setSeed((long) x * 341873128712L + (long) z * 132897987541L);
Block[] blocks = new Block[32768];
byte[] metadatas = new byte[blocks.length];
this.biomesForGeneration = this.endWorld.getWorldChunkManager()
.loadBlockGeneratorData(this.biomesForGeneration, x * 16, z * 16, 16,
16);
this.func_147420_a(x, z, blocks, this.biomesForGeneration);
this.replaceBiomeBlocks(x, z, blocks, this.biomesForGeneration, metadatas);
Chunk chunk = new Chunk(this.endWorld, blocks, metadatas, x, z);
short[] biomes = ((IChunkMixin) chunk).getBiomeShortArray();
for (int i = 0; i < biomes.length; ++i) {
biomes[i] = (short) this.biomesForGeneration[i].biomeID;
}
chunk.generateSkylightMap();
return chunk;
@Redirect(method = "provideChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B"),
require = 1)
private byte[] setBiomesTweaked(Chunk chunk) {
return BiomePatchHelper.getBiomeArrayTweaked(chunk, biomesForGeneration);
}
}
@@ -1,10 +1,17 @@
package com.falsepattern.endlessids.mixin.mixins.common.vanilla.worldgen;
import com.falsepattern.endlessids.EndlessIDs;
import com.falsepattern.endlessids.mixin.helpers.BiomePatchHelper;
import com.falsepattern.endlessids.mixin.helpers.IChunkMixin;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import net.minecraft.block.Block;
import net.minecraft.world.World;
@@ -19,63 +26,29 @@ import java.util.List;
@Mixin(ChunkProviderFlat.class)
public abstract class ChunkProviderFlatMixin implements IChunkProvider {
@Shadow
private World worldObj;
private BiomeGenBase[] bgb;
@Shadow
@Final
private Block[] cachedBlockIDs;
@Inject(method = "provideChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B",
shift = At.Shift.BEFORE),
locals = LocalCapture.CAPTURE_FAILHARD,
require = 1)
private void setBiomesTweaked1(int p_73154_1_, int p_73154_2_, CallbackInfoReturnable<Chunk> cir, Chunk chunk, BiomeGenBase[] abiomegenbase) {
bgb = abiomegenbase;
@Shadow
@Final
private byte[] cachedBlockMetadata;
}
@Shadow
@Final
private List structureGenerators;
/**
* @author FalsePattern
* @reason Direct port from dumped code
*/
@Overwrite
public Chunk provideChunk(int x, int z) {
Chunk chunk = new Chunk(this.worldObj, x, z);
for (int Y = 0; Y < this.cachedBlockIDs.length; ++Y) {
Block block = this.cachedBlockIDs[Y];
if (block != null) {
int ebsID = Y >> 4;
ExtendedBlockStorage ebs = chunk.getBlockStorageArray()[ebsID];
if (ebs == null) {
ebs = new ExtendedBlockStorage(Y, !this.worldObj.provider.hasNoSky);
chunk.getBlockStorageArray()[ebsID] = ebs;
}
for (int X = 0; X < 16; ++X) {
for (int Z = 0; Z < 16; ++Z) {
ebs.func_150818_a(X, Y & 15, Z, block);
ebs.setExtBlockMetadata(X, Y & 15, Z, this.cachedBlockMetadata[Y]);
}
}
}
@Redirect(method = "provideChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B"),
require = 1)
private byte[] setBiomesTweaked2(Chunk chunk) {
try {
return BiomePatchHelper.getBiomeArrayTweaked(chunk, bgb);
} finally {
bgb = null;
}
chunk.generateSkylightMap();
BiomeGenBase[] bgb = this.worldObj.getWorldChunkManager().loadBlockGeneratorData(null, x * 16, z * 16, 16, 16);
short[] biomeArray = ((IChunkMixin) chunk).getBiomeShortArray();
for (int i = 0; i < biomeArray.length; ++i) {
biomeArray[i] = (short) bgb[i].biomeID;
}
for (Object o : this.structureGenerators) {
MapGenBase structureGenerator = (MapGenBase) o;
structureGenerator.func_151539_a(this, this.worldObj, x, z, null);
}
chunk.generateSkylightMap();
return chunk;
}
}
@@ -1,10 +1,13 @@
package com.falsepattern.endlessids.mixin.mixins.common.vanilla.worldgen;
import com.falsepattern.endlessids.mixin.helpers.BiomePatchHelper;
import com.falsepattern.endlessids.mixin.helpers.IChunkMixin;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import net.minecraft.block.Block;
import net.minecraft.world.World;
@@ -22,65 +25,14 @@ import java.util.Random;
@Mixin(ChunkProviderGenerate.class)
public abstract class ChunkProviderGenerateMixin implements IChunkProvider {
@Shadow
private Random rand;
@Shadow
private BiomeGenBase[] biomesForGeneration;
@Shadow
private World worldObj;
@Shadow
private MapGenBase caveGenerator;
@Shadow
private MapGenBase ravineGenerator;
@Shadow
@Final
private boolean mapFeaturesEnabled;
@Shadow
private MapGenMineshaft mineshaftGenerator;
@Shadow
private MapGenVillage villageGenerator;
@Shadow
private MapGenStronghold strongholdGenerator;
@Shadow
private MapGenScatteredFeature scatteredFeatureGenerator;
@Shadow
public abstract void func_147424_a(int p_147424_1_, int p_147424_2_, Block[] p_147424_3_);
@Shadow
public abstract void replaceBlocksForBiome(int p_147422_1_, int p_147422_2_, Block[] p_147422_3_, byte[] p_147422_4_, BiomeGenBase[] p_147422_5_);
/**
* @author FalsePattern
* @reason Direct port from dumped code
*/
@Overwrite
public Chunk provideChunk(int x, int z) {
this.rand.setSeed((long) x * 341873128712L + (long) z * 132897987541L);
Block[] blocks = new Block[65536];
byte[] metadata = new byte[65536];
this.func_147424_a(x, z, blocks);
this.biomesForGeneration = this.worldObj.getWorldChunkManager()
.loadBlockGeneratorData(this.biomesForGeneration, x * 16, z * 16, 16,
16);
this.replaceBlocksForBiome(x, z, blocks, metadata, this.biomesForGeneration);
this.caveGenerator.func_151539_a(this, this.worldObj, x, z, blocks);
this.ravineGenerator.func_151539_a(this, this.worldObj, x, z, blocks);
if (this.mapFeaturesEnabled) {
this.mineshaftGenerator.func_151539_a(this, this.worldObj, x, z, blocks);
this.villageGenerator.func_151539_a(this, this.worldObj, x, z, blocks);
this.strongholdGenerator.func_151539_a(this, this.worldObj, x, z, blocks);
this.scatteredFeatureGenerator.func_151539_a(this, this.worldObj, x, z, blocks);
}
Chunk chunk = new Chunk(this.worldObj, blocks, metadata, x, z);
short[] biomes = ((IChunkMixin) chunk).getBiomeShortArray();
for (int i = 0; i < biomes.length; ++i) {
biomes[i] = (short) this.biomesForGeneration[i].biomeID;
}
chunk.generateSkylightMap();
return chunk;
@Redirect(method = "provideChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B"),
require = 1)
private byte[] setBiomesTweaked(Chunk chunk) {
return BiomePatchHelper.getBiomeArrayTweaked(chunk, biomesForGeneration);
}
}
@@ -1,9 +1,15 @@
package com.falsepattern.endlessids.mixin.mixins.common.vanilla.worldgen;
import com.falsepattern.endlessids.mixin.helpers.BiomePatchHelper;
import com.falsepattern.endlessids.mixin.helpers.IChunkMixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import net.minecraft.block.Block;
import net.minecraft.world.World;
@@ -18,44 +24,28 @@ import java.util.Random;
@Mixin(ChunkProviderHell.class)
public abstract class ChunkProviderHellMixin implements IChunkProvider {
private BiomeGenBase[] bgb;
@Shadow
public MapGenNetherBridge genNetherBridge;
@Shadow
private Random hellRNG;
@Shadow
private World worldObj;
@Shadow
private MapGenBase netherCaveGenerator;
@Inject(method = "provideChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B",
shift = At.Shift.BEFORE),
locals = LocalCapture.CAPTURE_FAILHARD,
require = 1)
private void setBiomesTweaked1(int p_73154_1_, int p_73154_2_, CallbackInfoReturnable<Chunk> cir, Block[] ablock, byte[] meta, BiomeGenBase[] abiomegenbase, Chunk chunk) {
bgb = abiomegenbase;
@Shadow
public abstract void func_147419_a(int p_147419_1_, int p_147419_2_, Block[] p_147419_3_);
}
@Shadow(remap = false)
public abstract void replaceBiomeBlocks(int p_147418_1_, int p_147418_2_, Block[] p_147418_3_, byte[] meta, BiomeGenBase[] biomes);
/**
* @author FalsePattern
* @reason Direct port from dumped code
*/
@Overwrite
public Chunk provideChunk(int x, int z) {
this.hellRNG.setSeed((long) x * 341873128712L + (long) z * 132897987541L);
Block[] blocks = new Block[32768];
byte[] metadata = new byte[blocks.length];
BiomeGenBase[] bgb = this.worldObj.getWorldChunkManager().loadBlockGeneratorData(null, x * 16, z * 16, 16, 16);
this.func_147419_a(x, z, blocks);
this.replaceBiomeBlocks(x, z, blocks, metadata, bgb);
this.netherCaveGenerator.func_151539_a(this, this.worldObj, x, z, blocks);
this.genNetherBridge.func_151539_a(this, this.worldObj, x, z, blocks);
Chunk chunk = new Chunk(this.worldObj, blocks, metadata, x, z);
short[] biomes = ((IChunkMixin) chunk).getBiomeShortArray();
for (int i = 0; i < biomes.length; ++i) {
biomes[i] = (short) bgb[i].biomeID;
@Redirect(method = "provideChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B"),
require = 1)
private byte[] setBiomesTweaked2(Chunk chunk) {
try {
return BiomePatchHelper.getBiomeArrayTweaked(chunk, bgb);
} finally {
bgb = null;
}
chunk.resetRelightChecks();
return chunk;
}
}