Fixed some bootup errors

This commit is contained in:
Frank 2021-12-07 18:12:09 +01:00
parent 6c89c76c26
commit 6b63be32b0
6 changed files with 66 additions and 28 deletions

View file

@ -1,13 +1,17 @@
package ru.betterend.mixin.common;
import java.util.Optional;
import java.util.Random;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.feature.EndCityFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator;
import net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -17,20 +21,24 @@ import ru.betterend.world.generator.GeneratorOptions;
@Mixin(EndCityFeature.class)
public class EndCityFeatureMixin {
@Inject(method = "isFeatureChunk", at = @At("HEAD"), cancellable = true)
private void be_isFeatureChunk(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long l, WorldgenRandom chunkRandom, ChunkPos pos, Biome biome, ChunkPos chunkPos, NoneFeatureConfiguration defaultFeatureConfig, LevelHeightAccessor levelHeightAccessor, CallbackInfoReturnable<Boolean> info) {
@Inject(method = "pieceGeneratorSupplier", at = @At("HEAD"), cancellable = true)
private static void be_isFeatureChunk(PieceGeneratorSupplier.Context<NoneFeatureConfiguration> context, CallbackInfoReturnable<Optional<PieceGenerator<NoneFeatureConfiguration>>> info) {
final ChunkPos pos = context.chunkPos();
final ChunkGenerator chunkGenerator = context.chunkGenerator();
final LevelHeightAccessor levelHeightAccessor = context.heightAccessor();
//TODO: 1.18 that is a different random source!
Random chunkRandom = new WorldgenRandom(new LegacyRandomSource(pos.x*pos.z));
if (GeneratorOptions.useNewGenerator()) {
int chance = GeneratorOptions.getEndCityFailChance();
if (chance == 0) {
info.setReturnValue(getYPositionForFeature(pos, chunkGenerator, levelHeightAccessor) >= 60);
info.cancel();
}
else if (chunkRandom.nextInt(chance) == 0) {
info.setReturnValue(getYPositionForFeature(pos, chunkGenerator, levelHeightAccessor) >= 60);
info.cancel();
if (chance == 0 || chunkRandom.nextInt(chance) == 0) {
if (!(getYPositionForFeature(pos, chunkGenerator, levelHeightAccessor) >= 60)){
info.cancel();
info.setReturnValue(Optional.empty());
}
}
else {
info.setReturnValue(false);
info.setReturnValue(Optional.empty());
info.cancel();
}
}