generated from QuiltMC/quilt-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/net/pixaurora/janerator/shade/method/PieShading.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.pixaurora.janerator.shade.method; | ||
|
||
import java.util.List; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import net.minecraft.util.Mth; | ||
import net.pixaurora.janerator.config.SerialType; | ||
import net.pixaurora.janerator.graphing.Coordinate; | ||
|
||
public class PieShading implements SimpleShadingMethod { | ||
public static final Codec<PieShading> CODEC = RecordCodecBuilder.create( | ||
instance -> instance.group( | ||
Codec.STRING.listOf().fieldOf("generator_keys").forGetter(PieShading::involvedGeneratorKeys) | ||
).apply(instance, PieShading::new) | ||
); | ||
public static final SerialType<ShadingMethod> TYPE = new SerialType<>("pie", CODEC); | ||
|
||
private final List<String> generatorKeys; | ||
|
||
private final double stepAmount; | ||
private final int maxSlice; | ||
|
||
public PieShading(List<String> generatorKeys) { | ||
this.generatorKeys = generatorKeys; | ||
|
||
this.stepAmount = 2 * Math.PI / (generatorKeys.size()); | ||
this.maxSlice = generatorKeys.size() - 1; | ||
} | ||
|
||
@Override | ||
public SerialType<? extends ShadingMethod> type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public List<String> involvedGeneratorKeys() { | ||
return this.generatorKeys; | ||
} | ||
|
||
private int getSlice(Coordinate pos) { | ||
int slice = Mth.floor((pos.angle() + Math.PI) / this.stepAmount); | ||
return Math.min(slice, maxSlice); // Because there is a straight 1-thick line that is out of bounds otherwise | ||
} | ||
|
||
@Override | ||
public String getShade(Coordinate pos) { | ||
return this.generatorKeys.get(this.getSlice(pos)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters