22
33import java .util .ArrayList ;
44import java .util .Collections ;
5+ import java .util .HashMap ;
56import java .util .List ;
67import java .util .Map ;
8+ import java .util .Map .Entry ;
79import java .util .Random ;
810import java .util .stream .Collectors ;
911
1214import com .mcmoddev .orespawn .api .IFeature ;
1315import com .mcmoddev .orespawn .api .OreSpawnAPI ;
1416import com .mcmoddev .orespawn .api .SpawnEntry ;
17+ import com .mcmoddev .orespawn .api .SpawnLogic ;
18+ import com .mcmoddev .orespawn .data .ReplacementsRegistry ;
19+ import com .mcmoddev .orespawn .impl .SpawnLogicImpl ;
1520
1621import net .minecraft .block .Block ;
22+ import net .minecraft .block .state .IBlockState ;
1723import net .minecraft .init .Blocks ;
1824import net .minecraft .item .ItemBlock ;
1925import net .minecraft .util .math .BlockPos ;
2632
2733public class OreSpawnWorldGen implements IWorldGenerator {
2834
29- private final Map <Integer , DimensionLogic > dimensions ;
35+ private final Map <Integer , List < SpawnEntry > > dimensions ;
3036 public static final List <Block > SPAWN_BLOCKS = new ArrayList <>();
3137
3238 @ SuppressWarnings ("unused" ) private final long nextL ;
3339
34- public OreSpawnWorldGen (Map <Integer , DimensionLogic > allDimensions , long nextLong ) {
40+ public OreSpawnWorldGen (Map <Integer , List < SpawnEntry > > allDimensions , long nextLong ) {
3541 this .dimensions = Collections .unmodifiableMap (allDimensions );
3642 this .nextL = nextLong ;
3743 if (SPAWN_BLOCKS .isEmpty ()) {
@@ -41,41 +47,39 @@ public OreSpawnWorldGen(Map<Integer, DimensionLogic> allDimensions, long nextLon
4147 SPAWN_BLOCKS .addAll (OreDictionary .getOres ("stone" ).stream ().filter (stack -> stack .getItem () instanceof ItemBlock ).map (stack -> ((ItemBlock ) stack .getItem ()).getBlock ()).collect (Collectors .toList ()));
4248 }
4349 }
44-
50+
4551 @ Override
4652 public void generate (Random random , int chunkX , int chunkZ , World world , IChunkGenerator chunkGenerator ,
4753 IChunkProvider chunkProvider ) {
48-
49- int thisDim = world .provider .getDimension ();
50- DimensionLogic dimensionLogic = this .dimensions .get (thisDim );
51- List <SpawnEntry > entries = new ArrayList <>();
5254
53- if ( dimensionLogic == null ) {
55+ int thisDim = world .provider .getDimension ();
56+ List <SpawnEntry > entries = this .dimensions .get (thisDim );
57+ if ( entries == null ) {
5458 // no logic for this dimension, if this is nether or end, just exit
5559 if ( thisDim == -1 || thisDim == 1 ) {
5660 return ;
5761 }
5862
59- dimensionLogic = this .dimensions .get (OreSpawnAPI .DIMENSION_WILDCARD );
60- if ( dimensionLogic == null ) {
61- OreSpawn .LOGGER .fatal ("no logic for dimension " +thisDim +" or for all dimensions" );
63+ entries = this .dimensions .get (OreSpawnAPI .DIMENSION_WILDCARD );
64+ if ( entries == null ) {
65+ OreSpawn .LOGGER .fatal ("no spawn entries for dimension " +thisDim +" or for all dimensions" );
6266 return ;
6367 }
64- entries .addAll (dimensionLogic .getEntries ());
6568 } else if ( thisDim != -1 && thisDim != 1 ) {
66- dimensionLogic = this .dimensions .get (OreSpawnAPI .DIMENSION_WILDCARD );
67- if ( dimensionLogic != null ) {
68- entries .addAll (dimensionLogic .getEntries ());
69+ if ( this .dimensions .get (OreSpawnAPI .DIMENSION_WILDCARD ) != null ) {
70+ entries .addAll (this .dimensions .get (OreSpawnAPI .DIMENSION_WILDCARD ));
6971 }
7072 }
7173
7274 for ( SpawnEntry sE : entries ) {
7375 Biome biome = world .getBiomeProvider ().getBiome (new BlockPos (chunkX *16 , 64 ,chunkZ *16 ));
74- // OreSpawn.LOGGER.fatal("Trying to generate in biome "+biome+" for spawn entry with block of type "+sE.getState());
7576 if ( sE .getBiomes ().contains (biome ) || sE .getBiomes ().equals (Collections .<Biome >emptyList ()) || sE .getBiomes ().isEmpty () ) {
7677 IFeature currentFeatureGen = sE .getFeatureGen ();
77- // what follows is a stop-gap
78- currentFeatureGen .generate (random , chunkX , chunkZ , world , chunkGenerator , chunkProvider , sE .getParameters (), sE .getState (), sE .getReplacement ());
78+ IBlockState replacement = sE .getReplacement ();
79+ if ( replacement == null ) {
80+ replacement = ReplacementsRegistry .getDimensionDefault (thisDim );
81+ }
82+ currentFeatureGen .generate (random , chunkX , chunkZ , world , chunkGenerator , chunkProvider , sE .getParameters (), sE .getState (), replacement );
7983 }
8084 }
8185 }
0 commit comments