45 lines
2.3 KiB
Java
45 lines
2.3 KiB
Java
package net.minecraft.world.level.levelgen.placement;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import java.util.Map;
|
|
import com.google.common.collect.ImmutableMap;
|
|
import net.minecraft.core.Registry;
|
|
import com.mojang.datafixers.types.DynamicOps;
|
|
import net.minecraft.world.level.levelgen.feature.Feature;
|
|
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
|
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
|
import net.minecraft.core.BlockPos;
|
|
import java.util.Random;
|
|
import net.minecraft.world.level.levelgen.ChunkGeneratorSettings;
|
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import com.mojang.datafixers.Dynamic;
|
|
import net.minecraft.world.level.levelgen.feature.configurations.DecoratorConfiguration;
|
|
|
|
public class ConfiguredDecorator<DC extends DecoratorConfiguration> {
|
|
public final FeatureDecorator<DC> decorator;
|
|
public final DC config;
|
|
|
|
public ConfiguredDecorator(final FeatureDecorator<DC> cjx, final Dynamic<?> dynamic) {
|
|
this((FeatureDecorator<DecoratorConfiguration>)cjx, cjx.createSettings(dynamic));
|
|
}
|
|
|
|
public ConfiguredDecorator(final FeatureDecorator<DC> cjx, final DC cgh) {
|
|
this.decorator = cjx;
|
|
this.config = cgh;
|
|
}
|
|
|
|
public <FC extends FeatureConfiguration, F extends Feature<FC>> boolean place(final LevelAccessor bju, final ChunkGenerator<? extends ChunkGeneratorSettings> bzx, final Random random, final BlockPos fk, final ConfiguredFeature<FC, F> ccz) {
|
|
return this.decorator.<FC, F>placeFeature(bju, bzx, random, fk, this.config, ccz);
|
|
}
|
|
|
|
public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
|
|
return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("name"), dynamicOps.createString(Registry.DECORATOR.getKey(this.decorator).toString()), dynamicOps.createString("config"), this.config.<T>serialize(dynamicOps).getValue())));
|
|
}
|
|
|
|
public static <T> ConfiguredDecorator<?> deserialize(final Dynamic<T> dynamic) {
|
|
final FeatureDecorator<? extends DecoratorConfiguration> cjx2 = Registry.DECORATOR.get(new ResourceLocation(dynamic.get("name").asString("")));
|
|
return new ConfiguredDecorator<>(cjx2, dynamic.get("config").orElseEmptyMap());
|
|
}
|
|
}
|