Skip to content

Commit

Permalink
Fix crashing with BCLib. Closes #149
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Jan 15, 2024
1 parent af667e8 commit 94d32a6
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class MixinTheEndBiomeSource implements IExtendedTheEndBiomeSource
@Final
private Holder<Biome> end;

@Unique
private boolean tbInitialized = false;

@Unique
private Registry<Biome> biomeRegistry;
@Unique
Expand Down Expand Up @@ -95,17 +98,29 @@ public void initializeForTerraBlender(RegistryAccess registryAccess, long seed)
this.midlandsArea = LayeredNoiseUtil.biomeArea(registryAccess, seed, TerraBlender.CONFIG.endMidlandsBiomeSize, midlands);
this.edgeArea = LayeredNoiseUtil.biomeArea(registryAccess, seed, TerraBlender.CONFIG.endEdgeBiomeSize, edge);
this.islandsArea = LayeredNoiseUtil.biomeArea(registryAccess, seed, TerraBlender.CONFIG.endIslandBiomeSize, edge);

// This may not be initialized with e.g. BCLib
this.tbInitialized = true;
}

@Inject(method = "collectPossibleBiomes", at=@At("HEAD"), cancellable = true)
@Inject(method = "collectPossibleBiomes", at=@At("RETURN"), cancellable = true)
protected void onCollectPossibleBiomes(CallbackInfoReturnable<Stream<Holder<Biome>>> cir)
{
cir.setReturnValue(this.tbPossibleBiomes.stream());
if (!this.tbInitialized)
return;

var builder = ImmutableSet.<Holder<Biome>>builder();
builder.addAll(cir.getReturnValue().collect(Collectors.toSet()));
builder.addAll(this.tbPossibleBiomes);
cir.setReturnValue(builder.build().stream());
}

@Inject(method = "getNoiseBiome", at=@At("HEAD"), cancellable = true)
public void onGetNoiseBiome(int x, int y, int z, Climate.Sampler sampler, CallbackInfoReturnable<Holder<Biome>> cir)
{
if (!this.tbInitialized)
return;

int blockX = QuartPos.toBlock(x);
int blockY = QuartPos.toBlock(y);
int blockZ = QuartPos.toBlock(z);
Expand Down

0 comments on commit 94d32a6

Please sign in to comment.