Search in sources :

Example 1 with GemsWorldGenerator

use of net.silentchaos512.gems.world.GemsWorldGenerator in project SilentGems by SilentChaos512.

the class GemsWorldGenerator method selectState.

/**
 * Selects an IBlockState for the config. For gems, it will normally choose one randomly each call. For essence ores,
 * it selects the appropriate ore.
 *
 * @param config
 * @param random
 * @return
 */
protected IBlockState selectState(ConfigOptionOreGen config, Random random, World world, int posX, int posZ) {
    if (config == GemsConfig.WORLD_GEN_GEMS) {
        EnumGem gem;
        if (GemsConfig.GEM_REGIONS_ENABLED) {
            // Gem Regions
            long dimension = (long) world.provider.getDimension();
            long cx = (long) posX / 16 / GemsConfig.GEM_REGIONS_SIZE;
            long cz = (long) posZ / 16 / GemsConfig.GEM_REGIONS_SIZE;
            long seed = (world.getSeed() << 40L) | ((dimension & 0xFF) << 32L) | ((cz & 0xFFFF) << 16L) | (cx & 0xFFFF);
            Random regionRandom = new Random(seed);
            EnumGem firstGem = EnumGem.values()[regionRandom.nextInt(16)];
            EnumGem secondGem = EnumGem.values()[regionRandom.nextInt(16)];
            if (regionRandom.nextFloat() < GemsConfig.GEM_REGIONS_SECOND_GEM_CHANCE && random.nextBoolean()) {
                gem = secondGem;
            } else {
                gem = firstGem;
            }
        } else {
            // Classic logic
            int meta = ((WeightedRandomItemSG) WeightedRandom.getRandomItem(random, GemsConfig.GEM_WEIGHTS)).getMeta();
            gem = EnumGem.values()[meta];
        }
        return ModBlocks.gemOre.getDefaultState().withProperty(EnumGem.VARIANT_GEM, gem);
    } else if (config == GemsConfig.WORLD_GEN_CHAOS) {
        return ModBlocks.essenceOre.getDefaultState().withProperty(BlockEssenceOre.VARIANT, BlockEssenceOre.Type.CHAOS);
    } else if (config == GemsConfig.WORLD_GEN_GEMS_DARK) {
        int meta = ((WeightedRandomItemSG) WeightedRandom.getRandomItem(random, GemsConfig.GEM_WEIGHTS_DARK)).getMeta();
        EnumGem gem = EnumGem.values()[meta];
        return ModBlocks.gemOreDark.getDefaultState().withProperty(EnumGem.VARIANT_GEM, gem);
    } else if (config == GemsConfig.WORLD_GEN_ENDER) {
        return ModBlocks.essenceOre.getDefaultState().withProperty(BlockEssenceOre.VARIANT, BlockEssenceOre.Type.ENDER);
    } else if (config == GemsConfig.WORLD_GEN_GEMS_LIGHT) {
        int meta = ((WeightedRandomItemSG) WeightedRandom.getRandomItem(random, GemsConfig.GEM_WEIGHTS_LIGHT)).getMeta();
        EnumGem gem = EnumGem.values()[meta];
        return ModBlocks.gemOreLight.getDefaultState().withProperty(EnumGem.VARIANT_GEM, gem);
    } else {
        SilentGems.logHelper.severe("GemsWorldGenerator - Unknown ore config: " + config.name);
        return null;
    }
}
Also used : Random(java.util.Random) WeightedRandom(net.minecraft.util.WeightedRandom) EnumGem(net.silentchaos512.gems.lib.EnumGem) WeightedRandomItemSG(net.silentchaos512.gems.util.WeightedRandomItemSG)

Example 2 with GemsWorldGenerator

use of net.silentchaos512.gems.world.GemsWorldGenerator in project SilentGems by SilentChaos512.

the class SilentGems method preInit.

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
    localizationHelper = new LocalizationHelper(MODID).setReplaceAmpersand(true);
    SilentLib.instance.registerLocalizationHelperForMod(MODID, localizationHelper);
    CommonItemStats.init();
    ToolHelper.init();
    GemsConfig.INSTANCE.init(event.getSuggestedConfigurationFile());
    registry.addRegistrationHandler(new ModEnchantments(), Enchantment.class);
    registry.addRegistrationHandler(new ModBlocks(), Block.class);
    registry.addRegistrationHandler(new ModItems(), Item.class);
    registry.addRegistrationHandler(new ModPotions(), Potion.class);
    registry.addRegistrationHandler(new ModRecipes(), IRecipe.class);
    ModParts.init();
    SoulSkill.init();
    GemsConfig.INSTANCE.loadModuleConfigs();
    // TODO: Achievements
    // World generation
    GameRegistry.registerWorldGenerator(new GemsWorldGenerator(), 0);
    GameRegistry.registerWorldGenerator(new GemsGeodeWorldGenerator(), -10);
    // Headcrumbs
    FMLInterModComms.sendMessage("headcrumbs", "add-username", Names.SILENT_CHAOS_512);
    // Load TCon compatibility stuff?
    if (Loader.isModLoaded("tconstruct")) {
        TConstructGemsCompat.preInit();
    }
    VeinMinerCompat.init();
    proxy.preInit(registry);
}
Also used : GemsGeodeWorldGenerator(net.silentchaos512.gems.world.GemsGeodeWorldGenerator) ModItems(net.silentchaos512.gems.init.ModItems) ModBlocks(net.silentchaos512.gems.init.ModBlocks) ModRecipes(net.silentchaos512.gems.init.ModRecipes) ModPotions(net.silentchaos512.gems.init.ModPotions) GemsWorldGenerator(net.silentchaos512.gems.world.GemsWorldGenerator) ModEnchantments(net.silentchaos512.gems.init.ModEnchantments) LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper) EventHandler(net.minecraftforge.fml.common.Mod.EventHandler)

Aggregations

Random (java.util.Random)1 WeightedRandom (net.minecraft.util.WeightedRandom)1 EventHandler (net.minecraftforge.fml.common.Mod.EventHandler)1 ModBlocks (net.silentchaos512.gems.init.ModBlocks)1 ModEnchantments (net.silentchaos512.gems.init.ModEnchantments)1 ModItems (net.silentchaos512.gems.init.ModItems)1 ModPotions (net.silentchaos512.gems.init.ModPotions)1 ModRecipes (net.silentchaos512.gems.init.ModRecipes)1 EnumGem (net.silentchaos512.gems.lib.EnumGem)1 WeightedRandomItemSG (net.silentchaos512.gems.util.WeightedRandomItemSG)1 GemsGeodeWorldGenerator (net.silentchaos512.gems.world.GemsGeodeWorldGenerator)1 GemsWorldGenerator (net.silentchaos512.gems.world.GemsWorldGenerator)1 LocalizationHelper (net.silentchaos512.lib.util.LocalizationHelper)1