[Change] Debug Placement Modifierers can have uniquie Captions

This commit is contained in:
Frank 2023-05-23 22:47:42 +02:00
parent e3037d84bf
commit 13e56d0a97

View file

@ -1,6 +1,9 @@
package org.betterx.bclib.api.v3.levelgen.features.placement;
import org.betterx.bclib.BCLib;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.levelgen.placement.PlacementContext;
@ -10,8 +13,20 @@ import net.minecraft.world.level.levelgen.placement.PlacementModifierType;
import java.util.stream.Stream;
public class Debug extends PlacementModifier {
public static final Debug INSTANCE = new Debug();
public static final Codec<Debug> CODEC = Codec.unit(Debug::new);
public static final Debug INSTANCE = new Debug("Placing at {}");
public static final Codec<Debug> CODEC = RecordCodecBuilder.create((instance) -> instance
.group(
Codec.STRING
.fieldOf("caption")
.orElse("Placing at {}")
.forGetter(cfg -> cfg.caption)
)
.apply(instance, Debug::new));
private final String caption;
public Debug(String caption) {
this.caption = caption;
}
@Override
public Stream<BlockPos> getPositions(
@ -19,6 +34,7 @@ public class Debug extends PlacementModifier {
RandomSource randomSource,
BlockPos blockPos
) {
BCLib.LOGGER.info(caption, blockPos);
return Stream.of(blockPos);
}