package org.cyclops.cyclopscore.config.extendedconfig;

import com.mojang.serialization.Codec;
import net.minecraft.core.Registry;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry;
import org.cyclops.cyclopscore.config.ConfigurableType;
import org.cyclops.cyclopscore.init.ModBase;

import java.util.function.Function;

/**
 * Config for foliage placer types.
 * @author rubensworks
 * @see ExtendedConfig
 */
public class FoliagePlacerConfig<T extends FoliagePlacer> extends ExtendedConfigForge<FoliagePlacerConfig<T>, FoliagePlacerType<T>> {

    public FoliagePlacerConfig(ModBase mod, String namedId, Function<FoliagePlacerConfig<T>, Codec<T>> codec) {
        super(mod, namedId, (eConfig) -> {
            FoliagePlacerType<T> type = new FoliagePlacerType<>(codec.apply(eConfig));
            type.setRegistryName(mod.getModId(), namedId);
            return type;
        });
    }

    @Override
    public void onForgeRegistered() {
        super.onForgeRegistered();
        // The following shouldn't be necessary, but foliage types don't work without it since MC 1.18
        Registry.register(Registry.FOLIAGE_PLACER_TYPES, getInstance().getRegistryName(), getInstance());
    }

    @Override
    public String getTranslationKey() {
        return "foliageplacer." + getMod().getModId() + "." + getNamedId();
    }

    // Needed for config gui
    @Override
    public String getFullTranslationKey() {
        return getTranslationKey();
    }

    @Override
    public ConfigurableType getConfigurableType() {
        return ConfigurableType.FOLIAGE_PLACER;
    }

    @Override
    public IForgeRegistry<? super FoliagePlacerType<T>> getRegistry() {
        return ForgeRegistries.FOLIAGE_PLACER_TYPES;
    }
}

@@ -92,44 +92,8 @@
 ec;%0A
-import net.minecraft.core.Registry;%0A
 impo
@@ -1072,311 +1072,8 @@
  %7D%0A%0A
-    @Override%0A    public void onForgeRegistered() %7B%0A        super.onForgeRegistered();%0A        // The following shouldn't be necessary, but foliage types don't work without it since MC 1.18%0A        Registry.register(Registry.FOLIAGE_PLACER_TYPES, getInstance().getRegistryName(), getInstance());%0A    %7D%0A%0A
     

Remove 1.18.1 hack for registering foliage placers