11package moddedmite .rustedironcore .api .event .handler ;
22
33import moddedmite .rustedironcore .api .event .EventHandler ;
4+ import moddedmite .rustedironcore .api .event .Handlers ;
45import moddedmite .rustedironcore .api .event .events .OreGenerationRegisterEvent ;
56import moddedmite .rustedironcore .api .world .Dimension ;
67import net .minecraft .BiomeDecorator ;
78import net .minecraft .World ;
89import net .minecraft .WorldGenMinable ;
910import org .jetbrains .annotations .ApiStatus ;
11+ import org .jetbrains .annotations .Nullable ;
1012
1113import java .util .*;
14+ import java .util .function .ToIntFunction ;
1215
1316public class OreGenerationHandler extends EventHandler <OreGenerationRegisterEvent > {
1417 private final Map <Dimension , List <Setting >> ORE_MAP = new HashMap <>();
1518
19+ public static final ToIntFunction <Random > NETHER_ORE_HEIGHT = r -> r .nextInt (108 ) + 10 ;
20+ private final Map <Dimension , ToIntFunction <Random >> ORE_HEIGHT_MAP = new HashMap <>();
21+
22+ public OreGenerationHandler () {
23+ this .ORE_HEIGHT_MAP .put (Dimension .NETHER , NETHER_ORE_HEIGHT );
24+ }
25+
1626 @ ApiStatus .Internal
1727 public void onOresGeneration (Context context ) {
1828 World world = context .world ;
@@ -36,11 +46,15 @@ public void unregisterOre(Dimension dimension, int blockId) {
3646 }
3747 }
3848
39- public static Context context (BiomeDecorator biomeDecorator , World world ) {
40- return new Context (biomeDecorator , world );
49+ public void setDimensionOreHeight (Dimension dimension , ToIntFunction <Random > height ) {
50+ this .ORE_HEIGHT_MAP .put (dimension , height );
51+ }
52+
53+ public static Context context (World world , @ Nullable BiomeDecorator biomeDecorator , Random random , int blockX , int blockZ ) {
54+ return new Context (world , biomeDecorator , random , blockX , blockZ );
4155 }
4256
43- public record Context (BiomeDecorator biomeDecorator , World world ) {
57+ public record Context (World world , @ Nullable BiomeDecorator biomeDecorator , Random random , int blockX , int blockZ ) {
4458 }
4559
4660 private static Setting setting (WorldGenMinable ore , int frequency , boolean increasesWithDepth ) {
@@ -49,7 +63,28 @@ private static Setting setting(WorldGenMinable ore, int frequency, boolean incre
4963
5064 private record Setting (WorldGenMinable ore , int frequency , boolean increasesWithDepth ) {
5165 private void generate (Context context ) {
52- context .biomeDecorator .genMinable (frequency , ore , increasesWithDepth );
66+ BiomeDecorator decorator = context .biomeDecorator ;
67+ if (decorator != null ) {
68+ decorator .genMinable (frequency , ore , increasesWithDepth );
69+ return ;
70+ }
71+ World world = context .world ;
72+ Dimension dimension = Dimension .fromWorld (world );
73+ ToIntFunction <Random > oreHeight ;
74+ if (dimension != null && Handlers .OreGeneration .ORE_HEIGHT_MAP .containsKey (dimension )) {
75+ oreHeight = Handlers .OreGeneration .ORE_HEIGHT_MAP .get (dimension );
76+ } else {
77+ oreHeight = NETHER_ORE_HEIGHT ;
78+ }
79+ Random random = context .random ;
80+ int blockX = context .blockX ;
81+ int blockZ = context .blockZ ;
82+ for (int i = 0 ; i < frequency ; i ++) {
83+ int x = blockX + random .nextInt (16 );
84+ int y = oreHeight .applyAsInt (random );
85+ int z = blockZ + random .nextInt (16 );
86+ ore .generate (world , random , x , y , z );
87+ }
5388 }
5489 }
5590}
0 commit comments