2020-02-11 07:12:23 +00:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright 2014 - 2019 , the Biomes O ' Plenty Team
*
* This work is licensed under a Creative Commons Attribution - NonCommercial - NoDerivatives 4 . 0 International Public License .
*
* To view a copy of this license , visit http : //creativecommons.org/licenses/by-nc-nd/4.0/.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
package biomesoplenty.common.biome ;
import biomesoplenty.api.biome.BOPBiomes ;
import biomesoplenty.api.enums.BOPClimates ;
2020-08-25 13:06:25 +00:00
import biomesoplenty.common.util.biome.BiomeUtil ;
2020-02-11 08:32:56 +00:00
import biomesoplenty.common.util.config.JsonUtil ;
2020-02-11 07:12:23 +00:00
import biomesoplenty.core.BiomesOPlenty ;
import biomesoplenty.init.ModBiomes ;
import com.google.common.collect.ImmutableMap ;
import com.google.common.collect.Lists ;
import com.google.common.collect.Maps ;
2020-02-14 00:01:09 +00:00
import com.google.common.collect.Sets ;
2020-02-11 08:32:56 +00:00
import com.google.gson.reflect.TypeToken ;
2020-09-07 02:10:07 +00:00
import net.minecraft.util.RegistryKey ;
2020-02-11 10:04:36 +00:00
import net.minecraft.util.ResourceLocation ;
2020-02-11 07:12:23 +00:00
import net.minecraft.world.biome.Biome ;
2020-02-11 08:32:56 +00:00
import net.minecraftforge.fml.loading.FMLPaths ;
2020-02-11 07:12:23 +00:00
import net.minecraftforge.registries.ForgeRegistries ;
2020-02-14 00:01:09 +00:00
import org.apache.commons.lang3.tuple.Pair ;
2020-02-11 08:32:56 +00:00
2020-09-07 02:10:07 +00:00
import javax.annotation.Nullable ;
2020-02-11 08:32:56 +00:00
import java.io.File ;
import java.nio.file.Path ;
import java.nio.file.Paths ;
2020-02-14 02:18:48 +00:00
import java.util.* ;
2020-02-11 07:12:23 +00:00
import java.util.function.Consumer ;
public class BiomeRegistry
{
2020-02-22 07:31:50 +00:00
private static final String CONFIG_FILE_NAME = " biomes.json " ;
2020-02-11 08:32:56 +00:00
2020-02-11 07:12:23 +00:00
private static Map < RegistrationType , List < DeferredRegistration > > deferrances = Maps . newHashMap ( ) ;
2020-08-20 10:18:53 +00:00
public static void deferStandardRegistration ( BiomeTemplate biome , String name )
2020-02-11 07:12:23 +00:00
{
defer ( RegistrationType . STANDARD_BIOME , new StandardBiomeRegistrationData ( biome , name ) ) ;
}
2020-08-20 10:18:53 +00:00
public static void deferTechnicalBiomeRegistration ( BiomeTemplate biome , String name )
2020-02-22 09:02:17 +00:00
{
defer ( RegistrationType . TECHNICAL_BIOME , new ToggleableStandardBiomeRegistrationData ( biome , name , true ) ) ;
}
2020-09-07 02:10:07 +00:00
public static void deferSubBiomeRegistration ( RegistryKey < Biome > parent , RegistryKey < Biome > child , int weight , float rarity )
2020-02-11 07:12:23 +00:00
{
2020-09-07 02:10:07 +00:00
// Don't register sub biome if the parent or child don't exist
2020-09-19 07:33:59 +00:00
if ( ! BiomeUtil . exists ( parent ) | | ! BiomeUtil . exists ( child ) ) {
2020-09-07 02:10:07 +00:00
return ;
2020-09-19 07:33:59 +00:00
}
2020-09-07 02:10:07 +00:00
2020-02-11 07:12:23 +00:00
defer ( RegistrationType . SUB_BIOME , new SubBiomeRegistrationData ( parent , child , weight , rarity ) ) ;
}
2020-09-07 02:10:07 +00:00
public static void deferIslandBiomeRegistration ( RegistryKey < Biome > key , BOPClimates climate , int weight )
2020-02-11 07:12:23 +00:00
{
2020-09-07 02:10:07 +00:00
if ( ! BiomeUtil . exists ( key ) )
return ;
defer ( RegistrationType . ISLAND_BIOME , new SingleClimateRegistrationData ( key , climate , weight ) ) ;
2020-02-18 11:53:47 +00:00
}
2020-09-07 02:10:07 +00:00
public static void deferVanillaBiomeRegistration ( RegistryKey < Biome > key , BOPClimates climate , int weight )
2020-02-18 11:53:47 +00:00
{
2020-09-07 02:10:07 +00:00
if ( ! BiomeUtil . exists ( key ) )
return ;
defer ( RegistrationType . VANILLA_BIOME , new SingleClimateRegistrationData ( key , climate , weight ) ) ;
2020-02-11 07:12:23 +00:00
}
2020-02-11 08:32:56 +00:00
public static void configureStandardBiomes ( )
{
List < DeferredRegistration > standardRegistrations = deferrances . get ( RegistrationType . STANDARD_BIOME ) ;
2020-02-18 11:53:47 +00:00
TreeMap < String , BiomeConfigData . WeightedBiomeEntry > defaultEntries = Maps . newTreeMap ( ) ;
2020-02-11 08:32:56 +00:00
Map < String , StandardBiomeRegistrationData > regDataMap = Maps . newHashMap ( ) ;
for ( DeferredRegistration < StandardBiomeRegistrationData > registration : standardRegistrations )
{
StandardBiomeRegistrationData regData = registration . regData ;
// Ignore biomes which don't have any weights set by default
2020-09-07 02:10:07 +00:00
if ( regData . getMetadata ( ) . hasWeights ( ) )
2020-02-11 08:32:56 +00:00
{
2020-02-11 10:04:36 +00:00
String biomeName = new ResourceLocation ( BiomesOPlenty . MOD_ID , regData . getName ( ) ) . toString ( ) ;
2020-02-14 00:01:09 +00:00
Pair < BOPClimates , Integer > primaryWeight = regData . getPrimaryWeight ( ) ;
2020-02-18 11:53:47 +00:00
defaultEntries . put ( biomeName , new BiomeConfigData . WeightedBiomeEntry ( primaryWeight . getValue ( ) ) ) ;
2020-02-11 10:04:36 +00:00
regDataMap . put ( biomeName , registration . regData ) ;
2020-02-11 08:32:56 +00:00
}
}
BiomeConfigData defaultConfigData = new BiomeConfigData ( ) ;
2020-02-14 00:01:09 +00:00
defaultConfigData . standardBiomeWeights = defaultEntries ;
2020-02-11 08:32:56 +00:00
BiomeConfigData configData = getConfigData ( defaultConfigData ) ;
2020-02-18 11:53:47 +00:00
TreeMap < String , BiomeConfigData . WeightedBiomeEntry > revisedStandardBiomeWeights = Maps . newTreeMap ( defaultEntries ) ;
2020-02-11 08:32:56 +00:00
// Merge the config file with the default values
2020-02-18 11:53:47 +00:00
for ( Map . Entry < String , BiomeConfigData . WeightedBiomeEntry > biomeEntry : configData . standardBiomeWeights . entrySet ( ) )
2020-02-11 08:32:56 +00:00
{
if ( revisedStandardBiomeWeights . containsKey ( biomeEntry . getKey ( ) ) )
{
revisedStandardBiomeWeights . put ( biomeEntry . getKey ( ) , biomeEntry . getValue ( ) ) ;
}
}
// Write back to the config file
configData . standardBiomeWeights = revisedStandardBiomeWeights ;
JsonUtil . writeFile ( getConfigFile ( ) , configData ) ;
2020-02-18 11:53:47 +00:00
for ( Map . Entry < String , BiomeConfigData . WeightedBiomeEntry > biomeEntry : configData . standardBiomeWeights . entrySet ( ) )
2020-02-11 08:32:56 +00:00
{
String name = biomeEntry . getKey ( ) ;
2020-02-18 11:53:47 +00:00
BiomeConfigData . WeightedBiomeEntry weight = biomeEntry . getValue ( ) ;
2020-02-11 08:32:56 +00:00
// Replace the default weight map for this biome with those from the config file
if ( regDataMap . containsKey ( name ) )
{
StandardBiomeRegistrationData registrationData = regDataMap . get ( name ) ;
2020-02-14 00:01:09 +00:00
registrationData . setPrimaryWeight ( weight . weight ) ;
2020-02-11 08:32:56 +00:00
}
}
}
2020-02-22 09:02:17 +00:00
public static void configureTechnicalBiomes ( )
{
List < DeferredRegistration > biomeRegistrations = deferrances . get ( RegistrationType . TECHNICAL_BIOME ) ;
TreeMap < String , BiomeConfigData . ToggleableBiomeEntry > defaultBiomeEntries = Maps . newTreeMap ( ) ;
for ( DeferredRegistration < ToggleableStandardBiomeRegistrationData > registration : biomeRegistrations )
{
ToggleableStandardBiomeRegistrationData regData = registration . regData ;
String biomeName = new ResourceLocation ( BiomesOPlenty . MOD_ID , regData . getName ( ) ) . toString ( ) ;
defaultBiomeEntries . put ( biomeName , new BiomeConfigData . ToggleableBiomeEntry ( true ) ) ;
}
BiomeConfigData defaultConfigData = new BiomeConfigData ( ) ;
defaultConfigData . technicalBiomeEntries = defaultBiomeEntries ;
BiomeConfigData configData = getConfigData ( defaultConfigData ) ;
TreeMap < String , BiomeConfigData . ToggleableBiomeEntry > revisedBiomeEntries = Maps . newTreeMap ( defaultBiomeEntries ) ;
// Merge the config file with the default values
for ( Map . Entry < String , BiomeConfigData . ToggleableBiomeEntry > biomeEntry : configData . technicalBiomeEntries . entrySet ( ) )
{
if ( revisedBiomeEntries . containsKey ( biomeEntry . getKey ( ) ) )
{
revisedBiomeEntries . put ( biomeEntry . getKey ( ) , biomeEntry . getValue ( ) ) ;
}
}
// Write back to the config file
configData . technicalBiomeEntries = revisedBiomeEntries ;
JsonUtil . writeFile ( getConfigFile ( ) , configData ) ;
for ( DeferredRegistration < ToggleableStandardBiomeRegistrationData > registration : biomeRegistrations )
{
ToggleableStandardBiomeRegistrationData regData = registration . regData ;
String biomeName = new ResourceLocation ( BiomesOPlenty . MOD_ID , regData . getName ( ) ) . toString ( ) ;
if ( revisedBiomeEntries . containsKey ( biomeName ) )
{
BiomeConfigData . ToggleableBiomeEntry entry = revisedBiomeEntries . get ( biomeName ) ;
if ( ! entry . enabled )
{
registration . regData . setEnabled ( false ) ;
}
}
}
}
2020-02-11 08:32:56 +00:00
public static void configureSubBiomes ( )
{
List < DeferredRegistration > subBiomeRegistrations = deferrances . get ( RegistrationType . SUB_BIOME ) ;
2020-02-14 02:18:48 +00:00
TreeMap < String , BiomeConfigData . SubBiomeEntry > defaultSubBiomeEntries = Maps . newTreeMap ( ) ;
2020-02-11 08:32:56 +00:00
Map < String , SubBiomeRegistrationData > regDataMap = Maps . newHashMap ( ) ;
for ( DeferredRegistration < SubBiomeRegistrationData > registration : subBiomeRegistrations )
{
SubBiomeRegistrationData regData = registration . regData ;
2020-09-07 02:10:07 +00:00
String biomeName = registration . regData . getChild ( ) . getRegistryName ( ) . toString ( ) ;
2020-02-11 08:32:56 +00:00
defaultSubBiomeEntries . put ( biomeName , new BiomeConfigData . SubBiomeEntry ( regData . getWeight ( ) , regData . getRarity ( ) ) ) ;
regDataMap . put ( biomeName , registration . regData ) ;
}
BiomeConfigData defaultConfigData = new BiomeConfigData ( ) ;
defaultConfigData . subBiomeEntries = defaultSubBiomeEntries ;
BiomeConfigData configData = getConfigData ( defaultConfigData ) ;
2020-02-14 02:18:48 +00:00
TreeMap < String , BiomeConfigData . SubBiomeEntry > revisedSubBiomeEntries = Maps . newTreeMap ( defaultSubBiomeEntries ) ;
2020-02-11 08:32:56 +00:00
// Merge the config file with the default values
for ( Map . Entry < String , BiomeConfigData . SubBiomeEntry > biomeEntry : configData . subBiomeEntries . entrySet ( ) )
{
if ( revisedSubBiomeEntries . containsKey ( biomeEntry . getKey ( ) ) )
{
revisedSubBiomeEntries . put ( biomeEntry . getKey ( ) , biomeEntry . getValue ( ) ) ;
}
}
// Write back to the config file
configData . subBiomeEntries = revisedSubBiomeEntries ;
JsonUtil . writeFile ( getConfigFile ( ) , configData ) ;
for ( Map . Entry < String , BiomeConfigData . SubBiomeEntry > biomeEntry : configData . subBiomeEntries . entrySet ( ) )
{
String name = biomeEntry . getKey ( ) ;
BiomeConfigData . SubBiomeEntry subBiomeEntry = biomeEntry . getValue ( ) ;
// Replace the default values for this biome with those from the config file
if ( regDataMap . containsKey ( name ) )
{
SubBiomeRegistrationData registrationData = regDataMap . get ( name ) ;
registrationData . setWeight ( subBiomeEntry . weight ) ;
registrationData . setRarity ( subBiomeEntry . rarity ) ;
}
}
}
public static void configureIslandBiomes ( )
{
2020-02-22 09:02:17 +00:00
List < DeferredRegistration > biomeRegistrations = deferrances . get ( RegistrationType . ISLAND_BIOME ) ;
TreeMap < String , BiomeConfigData . ToggleableBiomeEntry > defaultBiomeEntries = Maps . newTreeMap ( ) ;
2020-02-22 07:31:50 +00:00
2020-02-22 09:02:17 +00:00
for ( DeferredRegistration < SingleClimateRegistrationData > registration : biomeRegistrations )
2020-02-22 07:31:50 +00:00
{
SingleClimateRegistrationData regData = registration . regData ;
2020-09-07 02:10:07 +00:00
String biomeName = regData . getBiome ( ) . getRegistryName ( ) . toString ( ) ;
2020-02-22 07:31:50 +00:00
defaultBiomeEntries . put ( biomeName , new BiomeConfigData . ToggleableBiomeEntry ( true ) ) ;
}
BiomeConfigData defaultConfigData = new BiomeConfigData ( ) ;
defaultConfigData . islandBiomeEntries = defaultBiomeEntries ;
BiomeConfigData configData = getConfigData ( defaultConfigData ) ;
2020-02-22 09:02:17 +00:00
TreeMap < String , BiomeConfigData . ToggleableBiomeEntry > revisedBiomeEntries = Maps . newTreeMap ( defaultBiomeEntries ) ;
2020-02-22 07:31:50 +00:00
// Merge the config file with the default values
for ( Map . Entry < String , BiomeConfigData . ToggleableBiomeEntry > biomeEntry : configData . islandBiomeEntries . entrySet ( ) )
{
if ( revisedBiomeEntries . containsKey ( biomeEntry . getKey ( ) ) )
{
revisedBiomeEntries . put ( biomeEntry . getKey ( ) , biomeEntry . getValue ( ) ) ;
}
}
// Write back to the config file
configData . islandBiomeEntries = revisedBiomeEntries ;
JsonUtil . writeFile ( getConfigFile ( ) , configData ) ;
2020-02-22 09:02:17 +00:00
for ( DeferredRegistration < SingleClimateRegistrationData > registration : biomeRegistrations )
2020-02-22 07:31:50 +00:00
{
SingleClimateRegistrationData regData = registration . regData ;
2020-09-07 02:10:07 +00:00
String biomeName = regData . getBiome ( ) . getRegistryName ( ) . toString ( ) ;
2020-02-22 07:31:50 +00:00
if ( revisedBiomeEntries . containsKey ( biomeName ) )
{
BiomeConfigData . ToggleableBiomeEntry entry = revisedBiomeEntries . get ( biomeName ) ;
if ( ! entry . enabled )
{
registration . regData . setWeight ( 0 ) ;
}
}
}
2020-02-11 08:32:56 +00:00
}
2020-02-18 11:53:47 +00:00
public static void configureVanillaBiomes ( )
{
2020-02-22 09:02:17 +00:00
List < DeferredRegistration > biomeRegistrations = deferrances . get ( RegistrationType . VANILLA_BIOME ) ;
2020-02-18 11:53:47 +00:00
TreeMap < String , BiomeConfigData . WeightedBiomeEntry > defaultBiomeEntries = Maps . newTreeMap ( ) ;
Map < String , SingleClimateRegistrationData > regDataMap = Maps . newHashMap ( ) ;
2020-02-22 09:02:17 +00:00
for ( DeferredRegistration < SingleClimateRegistrationData > registration : biomeRegistrations )
2020-02-18 11:53:47 +00:00
{
SingleClimateRegistrationData regData = registration . regData ;
2020-09-07 02:10:07 +00:00
String biomeName = registration . regData . getBiome ( ) . getRegistryName ( ) . toString ( ) ;
2020-02-18 11:53:47 +00:00
defaultBiomeEntries . put ( biomeName , new BiomeConfigData . WeightedBiomeEntry ( regData . getWeight ( ) ) ) ;
regDataMap . put ( biomeName , registration . regData ) ;
}
BiomeConfigData defaultConfigData = new BiomeConfigData ( ) ;
defaultConfigData . vanillaBiomeEntries = defaultBiomeEntries ;
BiomeConfigData configData = getConfigData ( defaultConfigData ) ;
TreeMap < String , BiomeConfigData . WeightedBiomeEntry > revisedBiomeEntries = Maps . newTreeMap ( defaultBiomeEntries ) ;
// Merge the config file with the default values
for ( Map . Entry < String , BiomeConfigData . WeightedBiomeEntry > biomeEntry : configData . vanillaBiomeEntries . entrySet ( ) )
{
if ( revisedBiomeEntries . containsKey ( biomeEntry . getKey ( ) ) )
{
revisedBiomeEntries . put ( biomeEntry . getKey ( ) , biomeEntry . getValue ( ) ) ;
}
}
// Write back to the config file
configData . vanillaBiomeEntries = revisedBiomeEntries ;
JsonUtil . writeFile ( getConfigFile ( ) , configData ) ;
for ( Map . Entry < String , BiomeConfigData . WeightedBiomeEntry > biomeEntry : configData . vanillaBiomeEntries . entrySet ( ) )
{
String name = biomeEntry . getKey ( ) ;
BiomeConfigData . WeightedBiomeEntry islandBiomeEntry = biomeEntry . getValue ( ) ;
// Replace the default values for this biome with those from the config file
if ( regDataMap . containsKey ( name ) )
{
SingleClimateRegistrationData registrationData = regDataMap . get ( name ) ;
registrationData . setWeight ( islandBiomeEntry . weight ) ;
}
}
}
2020-02-11 08:32:56 +00:00
private static File getConfigDirFile ( )
{
Path configPath = FMLPaths . CONFIGDIR . get ( ) ;
Path bopConfigPath = Paths . get ( configPath . toAbsolutePath ( ) . toString ( ) , " biomesoplenty " ) ;
return bopConfigPath . toFile ( ) ;
}
private static File getConfigFile ( )
{
return new File ( getConfigDirFile ( ) , CONFIG_FILE_NAME ) ;
}
private static BiomeConfigData getConfigData ( BiomeConfigData defaultConfigData )
{
BiomeConfigData configData = JsonUtil . getOrCreateConfigFile ( getConfigDirFile ( ) , CONFIG_FILE_NAME , defaultConfigData , new TypeToken < BiomeConfigData > ( ) { } . getType ( ) ) ;
return configData ;
}
2020-09-07 02:10:07 +00:00
private static < T extends IRegistrationData > void defer ( RegistrationType type , T data )
2020-02-11 07:12:23 +00:00
{
if ( ! deferrances . containsKey ( type ) )
deferrances . put ( type , Lists . newArrayList ( ) ) ;
List < DeferredRegistration > list = deferrances . get ( type ) ;
list . add ( new DeferredRegistration ( type . regFunc , data ) ) ;
}
public static void finalizeRegistrations ( RegistrationType type )
{
if ( ! deferrances . containsKey ( type ) )
return ;
2020-02-14 00:01:09 +00:00
if ( type = = RegistrationType . SUB_BIOME )
{
2020-09-07 02:10:07 +00:00
Set < RegistryKey < Biome > > children = Sets . newHashSet ( ) ;
2020-02-14 00:01:09 +00:00
deferrances . get ( RegistrationType . SUB_BIOME ) . forEach ( ( reg ) - > {
2020-09-07 02:10:07 +00:00
RegistryKey < Biome > biome = ( ( SubBiomeRegistrationData ) reg . regData ) . getChild ( ) ;
2020-02-14 00:01:09 +00:00
if ( children . contains ( biome ) )
{
2020-09-07 02:10:07 +00:00
throw new RuntimeException ( String . format ( " Sub biome %s cannot be added to multiple parents " , biome . getRegistryName ( ) . toString ( ) ) ) ;
2020-02-14 00:01:09 +00:00
}
children . add ( biome ) ;
} ) ;
}
2020-02-11 07:12:23 +00:00
for ( DeferredRegistration reg : deferrances . get ( type ) )
{
reg . register ( ) ;
}
}
public enum RegistrationType
{
STANDARD_BIOME ( ( StandardBiomeRegistrationData data ) - > {
2020-09-07 02:10:07 +00:00
Biome biome = data . getBiome ( ) ;
BiomeMetadata metadata = data . getMetadata ( ) ;
2020-02-11 07:12:23 +00:00
String name = data . getName ( ) ;
// Don't register biomes with their weight set to 0, that normally have weights that are non-zero
2020-09-07 02:10:07 +00:00
if ( ! metadata . getWeightMap ( ) . isEmpty ( ) & & ( data . weightMap . isEmpty ( ) | | data . weightMap . entrySet ( ) . stream ( ) . allMatch ( ( entry ) - > entry . getValue ( ) . equals ( 0 ) ) ) )
2020-02-11 07:12:23 +00:00
{
2020-02-18 11:53:47 +00:00
BiomesOPlenty . logger . debug ( " Weights absent for " + data . getName ( ) + " , disabling... " ) ;
2020-02-11 07:12:23 +00:00
return ;
}
biome . setRegistryName ( name ) ;
ForgeRegistries . BIOMES . register ( biome ) ;
for ( Map . Entry < BOPClimates , Integer > entry : data . getWeights ( ) . entrySet ( ) )
{
if ( entry ! = null & & entry . getValue ( ) > 0 )
{
BOPClimates climate = entry . getKey ( ) ;
int weight = entry . getValue ( ) ;
2020-02-18 11:53:47 +00:00
BiomesOPlenty . logger . debug ( String . format ( " %s weight set to %d for climate %s " , name , weight , climate . name ( ) ) ) ;
2020-09-07 02:10:07 +00:00
climate . addBiome ( weight , BiomeUtil . createKey ( data . getBiome ( ) ) ) ;
2020-02-11 07:12:23 +00:00
}
}
2020-09-07 02:10:07 +00:00
if ( data . getMetadata ( ) ! = null )
2020-02-11 07:12:23 +00:00
{
2020-09-07 02:10:07 +00:00
ModBiomes . biomeMetadata . put ( BiomeUtil . createKey ( data . getBiome ( ) ) , data . getMetadata ( ) ) ;
2020-02-11 07:12:23 +00:00
}
} ) ,
2020-02-22 09:02:17 +00:00
TECHNICAL_BIOME ( ( ToggleableStandardBiomeRegistrationData data ) - > {
2020-09-07 02:10:07 +00:00
Biome biome = data . getBiome ( ) ;
2020-02-22 09:02:17 +00:00
String name = data . getName ( ) ;
if ( ! data . getEnabled ( ) )
{
BiomesOPlenty . logger . debug ( " Technical biome " + data . getName ( ) + " is disabled. " ) ;
return ;
}
biome . setRegistryName ( name ) ;
ForgeRegistries . BIOMES . register ( biome ) ;
2020-09-07 02:10:07 +00:00
if ( data . getMetadata ( ) ! = null )
2020-02-22 09:02:17 +00:00
{
2020-09-07 02:10:07 +00:00
ModBiomes . biomeMetadata . put ( BiomeUtil . createKey ( data . getBiome ( ) ) , data . getMetadata ( ) ) ;
2020-02-22 09:02:17 +00:00
}
} ) ,
2020-02-11 07:12:23 +00:00
SUB_BIOME ( ( SubBiomeRegistrationData data ) - > {
if ( data . getWeight ( ) = = 0 )
{
2020-09-07 02:10:07 +00:00
BiomesOPlenty . logger . debug ( " Weights absent for sub biome " + data . getChild ( ) . getRegistryName ( ) . toString ( ) + " , disabling... " ) ;
2020-02-11 07:12:23 +00:00
return ;
}
2020-09-07 02:10:07 +00:00
String childName = data . getChild ( ) . getRegistryName ( ) . toString ( ) ;
2020-02-18 11:53:47 +00:00
BiomesOPlenty . logger . debug ( String . format ( " Sub biome %s weight set to %d " , childName , data . getWeight ( ) ) ) ;
2020-08-25 13:06:25 +00:00
ModBiomes . subBiomes . put ( BiomeUtil . getBiomeId ( data . getParent ( ) ) , new ModBiomes . WeightedSubBiome ( data . getChild ( ) , data . getRarity ( ) , data . getWeight ( ) ) ) ;
2020-02-11 07:12:23 +00:00
} ) ,
2020-02-18 11:53:47 +00:00
ISLAND_BIOME ( ( SingleClimateRegistrationData data ) - > {
2020-02-11 07:12:23 +00:00
if ( data . getWeight ( ) = = 0 )
{
2020-09-07 02:10:07 +00:00
BiomesOPlenty . logger . debug ( " Weights absent for island biome " + data . getBiome ( ) . getRegistryName ( ) . toString ( ) + " , disabling... " ) ;
2020-02-11 07:12:23 +00:00
return ;
}
2020-09-07 02:10:07 +00:00
String biomeName = data . getBiome ( ) . getRegistryName ( ) . toString ( ) ;
2020-02-18 11:53:47 +00:00
BiomesOPlenty . logger . debug ( String . format ( " Island biome %s weight set to %d for climate %s " , biomeName , data . getWeight ( ) , data . getClimate ( ) . name ( ) ) ) ;
2020-08-25 13:06:25 +00:00
ModBiomes . islandBiomeIds . add ( BiomeUtil . getBiomeId ( data . getBiome ( ) ) ) ;
2020-02-11 07:12:23 +00:00
data . getClimate ( ) . addIslandBiome ( data . getWeight ( ) , data . getBiome ( ) ) ;
2020-02-18 11:53:47 +00:00
} ) ,
VANILLA_BIOME ( ( SingleClimateRegistrationData data ) - > {
if ( data . getWeight ( ) = = 0 )
{
2020-09-07 02:10:07 +00:00
BiomesOPlenty . logger . debug ( " Weights absent for vanilla biome " + data . getBiome ( ) . getRegistryName ( ) . toString ( ) + " , disabling... " ) ;
2020-02-18 11:53:47 +00:00
return ;
}
data . getClimate ( ) . addBiome ( data . getWeight ( ) , data . getBiome ( ) ) ;
2020-02-11 07:12:23 +00:00
} ) ;
2020-09-07 02:10:07 +00:00
public final Consumer < ? extends IRegistrationData > regFunc ;
2020-02-11 07:12:23 +00:00
2020-09-07 02:10:07 +00:00
RegistrationType ( Consumer < ? extends IRegistrationData > regFunc )
2020-02-11 07:12:23 +00:00
{
this . regFunc = regFunc ;
}
}
2020-09-07 02:10:07 +00:00
private interface IRegistrationData
{
}
private static abstract class TemplateRegistrationData implements IRegistrationData
2020-02-11 07:12:23 +00:00
{
private final Biome biome ;
2020-09-07 02:10:07 +00:00
private final BiomeMetadata metadata ;
2020-02-11 07:12:23 +00:00
2020-09-07 02:10:07 +00:00
public TemplateRegistrationData ( BiomeTemplate template )
{
this . biome = template . build ( ) ;
this . metadata = template . buildMetadata ( ) ;
}
public TemplateRegistrationData ( Biome biome )
2020-02-11 07:12:23 +00:00
{
this . biome = biome ;
2020-09-07 02:10:07 +00:00
this . metadata = null ;
2020-02-11 07:12:23 +00:00
}
public Biome getBiome ( )
{
return this . biome ;
}
2020-09-07 02:10:07 +00:00
@Nullable
public BiomeMetadata getMetadata ( )
{
return this . metadata ;
}
2020-02-11 07:12:23 +00:00
}
2020-09-07 02:10:07 +00:00
private static class StandardBiomeRegistrationData extends TemplateRegistrationData
2020-02-11 07:12:23 +00:00
{
private final String name ;
2020-02-11 08:32:56 +00:00
private Map < BOPClimates , Integer > weightMap ;
2020-02-11 07:12:23 +00:00
2020-08-20 10:18:53 +00:00
public StandardBiomeRegistrationData ( BiomeTemplate biome , String name )
2020-02-11 07:12:23 +00:00
{
super ( biome ) ;
this . name = name ;
2020-09-07 02:10:07 +00:00
this . weightMap = Maps . newHashMap ( this . getMetadata ( ) . getWeightMap ( ) ) ;
2020-02-14 00:01:09 +00:00
this . ensureSingleWeight ( ) ;
2020-02-11 07:12:23 +00:00
}
public String getName ( )
{
return this . name ;
}
public ImmutableMap < BOPClimates , Integer > getWeights ( )
{
return ImmutableMap . copyOf ( this . weightMap ) ;
}
public int getWeight ( BOPClimates climate )
{
return this . weightMap . get ( climate ) ;
}
public void setWeight ( BOPClimates climate , int weight )
{
this . weightMap . put ( climate , weight ) ;
2020-02-14 00:01:09 +00:00
this . ensureSingleWeight ( ) ;
}
public Pair < BOPClimates , Integer > getPrimaryWeight ( )
{
List < Pair < BOPClimates , Integer > > pairs = Lists . newArrayList ( ) ;
this . weightMap . entrySet ( ) . forEach ( ( entry ) - > pairs . add ( Pair . of ( entry . getKey ( ) , entry . getValue ( ) ) ) ) ;
return pairs . get ( 0 ) ;
}
public void setPrimaryWeight ( int value )
{
BOPClimates climate = this . getPrimaryWeight ( ) . getKey ( ) ;
this . setWeight ( climate , value ) ;
}
// This limitation is enforced for config file simplicity, and because we don't need it at this time
private void ensureSingleWeight ( )
{
if ( this . weightMap . size ( ) > 1 )
{
throw new RuntimeException ( String . format ( " %s cannot be assigned to multiple climates! \ n%s " , new ResourceLocation ( BiomesOPlenty . MOD_ID , name ) . toString ( ) , this . weightMap ) ) ;
}
2020-02-11 07:12:23 +00:00
}
}
2020-09-07 02:10:07 +00:00
private static class SubBiomeRegistrationData implements IRegistrationData
2020-02-11 07:12:23 +00:00
{
2020-09-07 02:10:07 +00:00
private final RegistryKey < Biome > parent ;
private final RegistryKey < Biome > child ;
2020-02-11 07:12:23 +00:00
private int weight ;
private float rarity ;
2020-09-07 02:10:07 +00:00
public SubBiomeRegistrationData ( RegistryKey < Biome > parent , RegistryKey < Biome > child , int weight , float rarity )
2020-02-11 07:12:23 +00:00
{
this . parent = parent ;
2020-09-07 02:10:07 +00:00
this . child = child ;
2020-02-11 07:12:23 +00:00
this . weight = weight ;
this . rarity = rarity ;
}
2020-09-07 02:10:07 +00:00
public RegistryKey < Biome > getParent ( )
2020-02-11 07:12:23 +00:00
{
return this . parent ;
}
2020-09-07 02:10:07 +00:00
public RegistryKey < Biome > getChild ( )
2020-02-11 07:12:23 +00:00
{
2020-09-07 02:10:07 +00:00
return this . child ;
2020-02-11 07:12:23 +00:00
}
public int getWeight ( )
{
return this . weight ;
}
public void setWeight ( int weight )
{
this . weight = weight ;
}
public float getRarity ( )
{
return this . rarity ;
}
public void setRarity ( float rarity )
{
this . rarity = rarity ;
}
}
2020-09-07 02:10:07 +00:00
private static class SingleClimateRegistrationData implements IRegistrationData
2020-02-11 07:12:23 +00:00
{
private final BOPClimates climate ;
2020-09-07 02:10:07 +00:00
private final RegistryKey < Biome > biome ;
2020-02-11 07:12:23 +00:00
private int weight ;
2020-09-07 02:10:07 +00:00
public SingleClimateRegistrationData ( RegistryKey < Biome > biome , BOPClimates climate , int weight )
2020-02-11 07:12:23 +00:00
{
2020-09-07 02:10:07 +00:00
this . biome = biome ;
2020-02-11 07:12:23 +00:00
this . climate = climate ;
this . weight = weight ;
}
2020-09-07 02:10:07 +00:00
public RegistryKey < Biome > getBiome ( )
{
return this . biome ;
}
2020-02-11 07:12:23 +00:00
public BOPClimates getClimate ( )
{
return this . climate ;
}
public int getWeight ( )
{
return this . weight ;
}
public void setWeight ( int weight )
{
this . weight = weight ;
}
}
2020-09-07 02:10:07 +00:00
private static class ToggleableStandardBiomeRegistrationData extends TemplateRegistrationData
2020-02-22 09:02:17 +00:00
{
private final String name ;
private boolean enabled ;
2020-09-07 02:10:07 +00:00
public ToggleableStandardBiomeRegistrationData ( BiomeTemplate biome , String name , boolean enabled )
2020-02-22 09:02:17 +00:00
{
super ( biome ) ;
this . name = name ;
this . enabled = enabled ;
}
public String getName ( )
{
return this . name ;
}
public boolean getEnabled ( )
{
return this . enabled ;
}
public void setEnabled ( boolean enabled )
{
this . enabled = enabled ;
}
}
2020-09-07 02:10:07 +00:00
private static class DeferredRegistration < T extends IRegistrationData >
2020-02-11 07:12:23 +00:00
{
private final Consumer < T > regFunc ;
private final T regData ;
public DeferredRegistration ( Consumer < T > regFunc , T regData )
{
this . regFunc = regFunc ;
this . regData = regData ;
}
public void register ( )
{
this . regFunc . accept ( this . regData ) ;
}
}
}