Skip to content

Commit

Permalink
use either codec to make single-generator shading require less input
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixaurora committed Oct 16, 2023
1 parent 8629480 commit 6a28d9a
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Codec;

import net.minecraft.world.level.chunk.ChunkGenerator;
Expand All @@ -12,7 +14,20 @@

public interface ShadingMethod extends SpecifiesType<ShadingMethod> {
public static final List<SerialType<ShadingMethod>> TYPES = new ArrayList<>(List.of(NormalShading.TYPE));
public static final Codec<ShadingMethod> CODEC = new SerialType.Group<>("Shading method", TYPES).dispatchCodec();
public static final Codec<ShadingMethod> BASE_CODEC = new SerialType.Group<>("Shading method", TYPES).dispatchCodec();
public static final Codec<ShadingMethod> CODEC = Codec.either(
ChunkGenerator.CODEC,
ShadingMethod.BASE_CODEC
).xmap(
either -> either.map(NormalShading::new, Function.identity()),
shading -> {
if (shading instanceof NormalShading basicShading) {
return Either.left(basicShading.generator());
} else {
return Either.right(shading);
}
}
);

public List<ShadeData> shadeIn(List<Coordinate> points);

Expand Down

0 comments on commit 6a28d9a

Please sign in to comment.