Fabric API

Fabric API

106M Downloads

[1.18.2][FAPI 48.0] BiomeModificationContextImpl.addCarver fails for Biomes without initial carvers

quiqueck opened this issue ยท 1 comments

commented

Adding a new Carver assumes, that the generationSettings of a Biome have a valid RegistryEntryList for the given GenerationStep.

generationSettings.carvers.put(step, plus(generationSettings.carvers.get(step), carvers.getEntry(entry).orElseThrow()));

However the vanilla Biome Builder will initialize Biomes with an empty map, which will cause a NullPointerException in the plus-Method:

List<RegistryEntry<T>> list = new ArrayList<>(values.stream().toList());

A possible solution might be to amend values.stream().toList() with values==null?Lists.newArrayList():values.stream().toList() or something similar.

commented

Mixin can be used to temporarily overcome this problem

import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryEntryList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(targets = "net.fabricmc.fabric.impl.biome.modification.BiomeModificationContextImpl$GenerationSettingsContextImpl")
public class FapiCarverFixMixin {
    @Inject(method = "plus", at = @At("HEAD"), cancellable = true)
    private void fixPlus(RegistryEntryList<?> values, RegistryEntry<?> entry, CallbackInfoReturnable<RegistryEntryList<?>> cir) {
        if (values == null) {
            cir.setReturnValue(RegistryEntryList.of(entry));
        }
    }
}