Veins ore generation system. WIP.

This commit is contained in:
Dragon2488 2016-08-01 01:12:55 +07:00
parent 5898de8d8f
commit c8301e4db3
7 changed files with 529 additions and 306 deletions

View file

@ -42,166 +42,159 @@ import techreborn.proxies.CommonProxy;
import techreborn.tiles.idsu.IDSUManager;
import techreborn.utils.StackWIPHandler;
import techreborn.world.TechRebornWorldGen;
import techreborn.world.VeinWorldGenerator;
import java.io.File;
@Mod(modid = ModInfo.MOD_ID, name = ModInfo.MOD_NAME, version = ModInfo.MOD_VERSION, dependencies = ModInfo.MOD_DEPENDENCIES, guiFactory = ModInfo.GUI_FACTORY_CLASS, acceptedMinecraftVersions = "[1.9.4]")
public class Core
{
public class Core {
public Core() {
//Forge says to call it here, so yeah
FluidRegistry.enableUniversalBucket();
}
public Core() {
//Forge says to call it here, so yeah
FluidRegistry.enableUniversalBucket();
}
public static ConfigTechReborn config;
public static ConfigTechReborn config;
@SidedProxy(clientSide = ModInfo.CLIENT_PROXY_CLASS, serverSide = ModInfo.SERVER_PROXY_CLASS)
public static CommonProxy proxy;
@SidedProxy(clientSide = ModInfo.CLIENT_PROXY_CLASS, serverSide = ModInfo.SERVER_PROXY_CLASS)
public static CommonProxy proxy;
@Mod.Instance
public static Core INSTANCE;
public static LogHelper logHelper = new LogHelper(new ModInfo());
public static TechRebornWorldGen worldGen;
public static File configDir;
public VersionChecker versionChecker;
@Mod.Instance
public static Core INSTANCE;
public static LogHelper logHelper = new LogHelper(new ModInfo());
//public static TechRebornWorldGen worldGen;
public static File configDir;
public VersionChecker versionChecker;
@Mod.EventHandler
public void preinit(FMLPreInitializationEvent event) throws IllegalAccessException, InstantiationException {
event.getModMetadata().version = ModInfo.MOD_VERSION;
INSTANCE = this;
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);
@Mod.EventHandler
public void preinit(FMLPreInitializationEvent event) throws IllegalAccessException, InstantiationException {
event.getModMetadata().version = ModInfo.MOD_VERSION;
INSTANCE = this;
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);
configDir = new File(event.getModConfigurationDirectory(), "techreborn");
if (!configDir.exists())
{
configDir.mkdir();
}
config = ConfigTechReborn.initialize(new File(configDir, "main.cfg"));
worldGen = new TechRebornWorldGen();
worldGen.configFile = (new File(configDir, "ores.json"));
worldGen.hConfigFile = (new File(configDir, "ores.hjson"));
configDir = new File(event.getModConfigurationDirectory(), "techreborn");
if (!configDir.exists()) {
configDir.mkdir();
}
config = ConfigTechReborn.initialize(new File(configDir, "main.cfg"));
//worldGen = new TechRebornWorldGen();
//worldGen.configFile = (new File(configDir, "ores.json"));
//worldGen.hConfigFile = (new File(configDir, "ores.hjson"));
TechRebornAPI.subItemRetriever = new SubItemRetriever();
TechRebornAPI.subItemRetriever = new SubItemRetriever();
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules)
{
compatModule.preInit(event);
}
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
compatModule.preInit(event);
}
// Register ModBlocks
ModBlocks.init();
// Register Fluids
ModFluids.init();
// Register ModItems
ModItems.init();
// Entitys
EntityRegistry.registerModEntity(EntityNukePrimed.class, "nuke", 0, INSTANCE, 160, 5, true);
// Register ModBlocks
ModBlocks.init();
// Register Fluids
ModFluids.init();
// Register ModItems
ModItems.init();
// Entitys
EntityRegistry.registerModEntity(EntityNukePrimed.class, "nuke", 0, INSTANCE, 160, 5, true);
proxy.preInit(event);
proxy.preInit(event);
RecipeConfigManager.load(event.getModConfigurationDirectory());
RecipeConfigManager.load(event.getModConfigurationDirectory());
versionChecker = new VersionChecker("TechReborn", new ModInfo());
versionChecker.checkVersionThreaded();
logHelper.info("PreInitialization Complete");
}
versionChecker = new VersionChecker("TechReborn", new ModInfo());
versionChecker.checkVersionThreaded();
logHelper.info("PreInitialization Complete");
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) throws IllegalAccessException, InstantiationException
{
// Registers Chest Loot
ModLoot.init();
// Multiparts
ModParts.init();
// Sounds
ModSounds.init();
// Compat
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules)
{
compatModule.init(event);
}
MinecraftForge.EVENT_BUS.register(new StackWIPHandler());
@Mod.EventHandler
public void init(FMLInitializationEvent event) throws IllegalAccessException, InstantiationException {
//World gen
VeinWorldGenerator.registerTRVeins();
GameRegistry.registerWorldGenerator(VeinWorldGenerator.INSTANCE, 0);
// Registers Chest Loot
ModLoot.init();
// Multiparts
ModParts.init();
// Sounds
ModSounds.init();
// Compat
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
compatModule.init(event);
}
MinecraftForge.EVENT_BUS.register(new StackWIPHandler());
//Ore Dictionary
OreDict.init();
//Ore Dictionary
OreDict.init();
// Recipes
StopWatch watch = new StopWatch();
watch.start();
ModRecipes.init();
logHelper.all(watch + " : main recipes");
watch.stop();
// Client only init, needs to be done before parts system
proxy.init(event);
// WorldGen
worldGen.load();
GameRegistry.registerWorldGenerator(worldGen, 0);
// DungeonLoot.init();
// Register Gui Handler
NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());
// Recipes
StopWatch watch = new StopWatch();
watch.start();
ModRecipes.init();
logHelper.all(watch + " : main recipes");
watch.stop();
// Client only init, needs to be done before parts system
proxy.init(event);
// WorldGen
//worldGen.load();
//GameRegistry.registerWorldGenerator(worldGen, 0);
// Achievements
TRAchievements.init();
// Multiblock events
MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler());
// IDSU manager
IDSUManager.INSTANCE = new IDSUManager();
// Event busses
MinecraftForge.EVENT_BUS.register(IDSUManager.INSTANCE);
MinecraftForge.EVENT_BUS.register(new MultiblockServerTickHandler());
MinecraftForge.EVENT_BUS.register(new TRTickHandler());
MinecraftForge.EVENT_BUS.register(new OreUnifier());
MinecraftForge.EVENT_BUS.register(worldGen.retroGen);
// Scrapbox
if (config.ScrapboxDispenser)
{
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(ModItems.scrapBox, new BehaviorDispenseScrapbox());
}
logHelper.info("Initialization Complete");
}
// DungeonLoot.init();
// Register Gui Handler
NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());
@Mod.EventHandler
public void postinit(FMLPostInitializationEvent event) throws Exception
{
// Has to be done here as Buildcraft registers their recipes late
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules)
{
compatModule.postInit(event);
}
proxy.postInit(event);
logHelper.info(RecipeHandler.recipeList.size() + " recipes loaded");
// Achievements
TRAchievements.init();
// Multiblock events
MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler());
// IDSU manager
IDSUManager.INSTANCE = new IDSUManager();
// Event busses
MinecraftForge.EVENT_BUS.register(IDSUManager.INSTANCE);
MinecraftForge.EVENT_BUS.register(new MultiblockServerTickHandler());
MinecraftForge.EVENT_BUS.register(new TRTickHandler());
MinecraftForge.EVENT_BUS.register(new OreUnifier());
//MinecraftForge.EVENT_BUS.register(worldGen.retroGen);
// Scrapbox
if (config.ScrapboxDispenser) {
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(ModItems.scrapBox, new BehaviorDispenseScrapbox());
}
logHelper.info("Initialization Complete");
}
// RecipeHandler.scanForDupeRecipes();
@Mod.EventHandler
public void postinit(FMLPostInitializationEvent event) throws Exception {
// Has to be done here as Buildcraft registers their recipes late
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
compatModule.postInit(event);
}
proxy.postInit(event);
logHelper.info(RecipeHandler.recipeList.size() + " recipes loaded");
// RecipeConfigManager.save();
//recipeCompact.saveMissingItems(configDir);
}
// RecipeHandler.scanForDupeRecipes();
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event)
{
event.registerServerCommand(new TechRebornDevCommand());
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules)
{
compatModule.serverStarting(event);
}
}
// RecipeConfigManager.save();
//recipeCompact.saveMissingItems(configDir);
}
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent cfgChange)
{
if (cfgChange.getModID().equals("TechReborn"))
{
ConfigTechReborn.Configs();
}
}
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event) {
event.registerServerCommand(new TechRebornDevCommand());
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
compatModule.serverStarting(event);
}
}
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent cfgChange) {
if (cfgChange.getModID().equals("TechReborn")) {
ConfigTechReborn.Configs();
}
}
@SubscribeEvent
public void addDiscriminator(AddDiscriminatorEvent event) {
event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketAesu.class);
event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketIdsu.class);
}
@SubscribeEvent
public void addDiscriminator(AddDiscriminatorEvent event)
{
event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketAesu.class);
event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketIdsu.class);
}
}

View file

@ -34,152 +34,134 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvider
{
public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvider {
public static final String[] ores = new String[] { "galena", "iridium", "ruby", "sapphire", "bauxite", "pyrite",
"cinnabar", "sphalerite", "tungston", "sheldonite", "peridot", "sodalite",
"lead", "silver" };
static List<String> oreNamesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(ores));
public PropertyString VARIANTS = new PropertyString("type", oreNamesList);
public static final String[] ores = new String[]{
"galena", "iridium", "ruby", "sapphire", "bauxite", "pyrite",
"cinnabar", "sphalerite", "tungsten", "sheldonite", "peridot", "sodalite",
"lead", "silver"};
public BlockOre(Material material)
{
super(material);
setUnlocalizedName("techreborn.ore");
setCreativeTab(TechRebornCreativeTabMisc.instance);
setHardness(2.0f);
setHarvestLevel("pickaxe", 2);
this.setDefaultState(this.getStateFromMeta(0));
}
private static final List<String> oreNamesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(ores));
public static ItemStack getOreByName(String name, int count)
{
for (int i = 0; i < ores.length; i++)
{
if (ores[i].equalsIgnoreCase(name))
{
return new ItemStack(ModBlocks.ore, count, i);
}
}
return BlockOre2.getOreByName(name, count);
}
public static final PropertyString VARIANTS = new PropertyString("type", oreNamesList);
public static ItemStack getOreByName(String name)
{
return getOreByName(name, 1);
}
public BlockOre(Material material) {
super(material);
setUnlocalizedName("techreborn.ore");
setCreativeTab(TechRebornCreativeTabMisc.instance);
setHardness(2.0f);
setHarvestLevel("pickaxe", 2);
this.setDefaultState(this.getStateFromMeta(0));
}
public IBlockState getBlockStateFromName(String name)
{
int index = -1;
for (int i = 0; i < ores.length; i++)
{
if (ores[i].equalsIgnoreCase(name))
{
index = i;
break;
}
}
if (index == -1)
{
return ModBlocks.ore2.getBlockStateFromName(name);
}
return getStateFromMeta(index);
}
public static ItemStack getOreByName(String name, int count) {
for (int i = 0; i < ores.length; i++) {
if (ores[i].equalsIgnoreCase(name)) {
return new ItemStack(ModBlocks.ore, count, i);
}
}
return BlockOre2.getOreByName(name, count);
}
@Deprecated
public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
String variant = state.getValue(VARIANTS);
int meta = getMetaFromState(state);
Random random = new Random();
// Ruby
if (variant.equalsIgnoreCase("Ruby"))
{
OreDrop ruby = new OreDrop(ItemGems.getGemByName("ruby"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop redGarnet = new OreDrop(ItemGems.getGemByName("redGarnet"), 0.02);
OreDropSet set = new OreDropSet(ruby, redGarnet);
return set.drop(fortune, random);
}
public static ItemStack getOreByName(String name) {
return getOreByName(name, 1);
}
// Sapphire
if (variant.equalsIgnoreCase("Sapphire"))
{
OreDrop sapphire = new OreDrop(ItemGems.getGemByName("sapphire"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop peridot = new OreDrop(ItemGems.getGemByName("peridot"), 0.03);
OreDropSet set = new OreDropSet(sapphire, peridot);
return set.drop(fortune, random);
}
public IBlockState getBlockStateFromName(String name) {
int index = -1;
for (int i = 0; i < ores.length; i++) {
if (ores[i].equalsIgnoreCase(name)) {
index = i;
break;
}
}
if (index == -1) {
return ModBlocks.ore2.getBlockStateFromName(name);
}
return getStateFromMeta(index);
}
// Pyrite
if (variant.equalsIgnoreCase("Pyrite"))
{
OreDrop pyriteDust = new OreDrop(ItemDusts.getDustByName("pyrite"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDropSet set = new OreDropSet(pyriteDust);
return set.drop(fortune, random);
}
@Deprecated
public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
String variant = state.getValue(VARIANTS);
int meta = getMetaFromState(state);
Random random = new Random();
// Ruby
if (variant.equalsIgnoreCase("Ruby")) {
OreDrop ruby = new OreDrop(ItemGems.getGemByName("ruby"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop redGarnet = new OreDrop(ItemGems.getGemByName("redGarnet"), 0.02);
OreDropSet set = new OreDropSet(ruby, redGarnet);
return set.drop(fortune, random);
}
// Sodalite
if (variant.equalsIgnoreCase("Sodalite"))
{
OreDrop sodalite = new OreDrop(ItemDusts.getDustByName("sodalite", 6),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop aluminum = new OreDrop(ItemDusts.getDustByName("aluminum"), 0.50);
OreDropSet set = new OreDropSet(sodalite, aluminum);
return set.drop(fortune, random);
}
// Sapphire
if (variant.equalsIgnoreCase("Sapphire")) {
OreDrop sapphire = new OreDrop(ItemGems.getGemByName("sapphire"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop peridot = new OreDrop(ItemGems.getGemByName("peridot"), 0.03);
OreDropSet set = new OreDropSet(sapphire, peridot);
return set.drop(fortune, random);
}
// Cinnabar
if (variant.equalsIgnoreCase("Cinnabar"))
{
OreDrop cinnabar = new OreDrop(ItemDusts.getDustByName("cinnabar"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop redstone = new OreDrop(new ItemStack(Items.REDSTONE), 0.25);
OreDropSet set = new OreDropSet(cinnabar, redstone);
return set.drop(fortune, random);
}
// Pyrite
if (variant.equalsIgnoreCase("Pyrite")) {
OreDrop pyriteDust = new OreDrop(ItemDusts.getDustByName("pyrite"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDropSet set = new OreDropSet(pyriteDust);
return set.drop(fortune, random);
}
// Sphalerite 1, 1/8 yellow garnet
if (variant.equalsIgnoreCase("Sphalerite"))
{
OreDrop sphalerite = new OreDrop(ItemDusts.getDustByName("sphalerite"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop yellowGarnet = new OreDrop(ItemGems.getGemByName("yellowGarnet"), 0.125);
OreDropSet set = new OreDropSet(sphalerite, yellowGarnet);
return set.drop(fortune, random);
}
// Sodalite
if (variant.equalsIgnoreCase("Sodalite")) {
OreDrop sodalite = new OreDrop(ItemDusts.getDustByName("sodalite", 6),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop aluminum = new OreDrop(ItemDusts.getDustByName("aluminum"), 0.50);
OreDropSet set = new OreDropSet(sodalite, aluminum);
return set.drop(fortune, random);
}
ArrayList<ItemStack> block = new ArrayList<>();
block.add(new ItemStack(Item.getItemFromBlock(this), 1, meta));
return block;
}
// Cinnabar
if (variant.equalsIgnoreCase("Cinnabar")) {
OreDrop cinnabar = new OreDrop(ItemDusts.getDustByName("cinnabar"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop redstone = new OreDrop(new ItemStack(Items.REDSTONE), 0.25);
OreDropSet set = new OreDropSet(cinnabar, redstone);
return set.drop(fortune, random);
}
@Override
protected boolean canSilkHarvest()
{
return true;
}
// Sphalerite 1, 1/8 yellow garnet
if (variant.equalsIgnoreCase("Sphalerite")) {
OreDrop sphalerite = new OreDrop(ItemDusts.getDustByName("sphalerite"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
OreDrop yellowGarnet = new OreDrop(ItemGems.getGemByName("yellowGarnet"), 0.125);
OreDropSet set = new OreDropSet(sphalerite, yellowGarnet);
return set.drop(fortune, random);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list)
{
for (int meta = 0; meta < ores.length; meta++)
{
list.add(new ItemStack(item, 1, meta));
}
}
ArrayList<ItemStack> block = new ArrayList<>();
block.add(new ItemStack(Item.getItemFromBlock(this), 1, meta));
return block;
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,
EntityPlayer player)
{
return new ItemStack(this,1, getMetaFromState(state));
}
@Override
protected boolean canSilkHarvest() {
return true;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) {
for (int meta = 0; meta < ores.length; meta++) {
list.add(new ItemStack(item, 1, meta));
}
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,
EntityPlayer player) {
return new ItemStack(this, 1, getMetaFromState(state));
}
// @Override
// public int damageDropped(IBlockState state)
@ -198,45 +180,41 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
// return meta;
// }
@Override
public String getTextureNameFromState(IBlockState BlockStateContainer, EnumFacing facing)
{
return "techreborn:blocks/ore/ore" + StringUtils.toFirstCapital(ores[getMetaFromState(BlockStateContainer)]);
}
@Override
public String getTextureNameFromState(IBlockState BlockStateContainer, EnumFacing facing) {
return "techreborn:blocks/ore/ore" + StringUtils.toFirstCapital(ores[getMetaFromState(BlockStateContainer)]);
}
@Override
public int amountOfStates()
{
return ores.length;
}
@Override
public int amountOfStates() {
return ores.length;
}
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
@Override
public IBlockState getStateFromMeta(int meta) {
if(meta > ores.length){
meta = 0;
}
return getBlockState().getBaseState().withProperty(VARIANTS, oreNamesList.get(meta));
}
@Override
public IBlockState getStateFromMeta(int meta) {
if (meta > ores.length) {
meta = 0;
}
return getBlockState().getBaseState().withProperty(VARIANTS, oreNamesList.get(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return oreNamesList.indexOf(state.getValue(VARIANTS));
}
@Override
public int getMetaFromState(IBlockState state) {
return oreNamesList.indexOf(state.getValue(VARIANTS));
}
protected BlockStateContainer createBlockState()
{
VARIANTS = new PropertyString("type", oreNamesList);
return new BlockStateContainer(this, VARIANTS);
}
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, VARIANTS);
}
@Override
public String getUserLoclisedName(IBlockState state) {
return StringUtils.toFirstCapital(oreNamesList.get(getMetaFromState(state)));
}
@Override
public String getUserLoclisedName(IBlockState state)
{
return StringUtils.toFirstCapital(oreNamesList.get(getMetaFromState(state)));
}
}

View file

@ -72,9 +72,8 @@ public class BlockOre2 extends BaseBlock implements ITexturedBlock, IOreNameProv
break;
}
}
if (index == -1)
{
return ModBlocks.ore2.getBlockStateFromName(name);
if (index == -1) {
throw new InvalidParameterException("The ore block " + name + " could not be found.");
}
return getStateFromMeta(index);
}

View file

@ -64,7 +64,7 @@ public class TechRebornWorldGen implements IWorldGenerator
defaultConfig.neatherOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Cinnabar"), 6, 3, 10, 250));
defaultConfig.neatherOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Sphalerite"), 6, 3, 10, 250));
defaultConfig.endOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Tungston"), 6, 3, 10, 250));
defaultConfig.endOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Tungsten"), 6, 3, 10, 250));
defaultConfig.endOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Sheldonite"), 6, 3, 10, 250));
defaultConfig.endOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Peridot"), 6, 3, 10, 250));
defaultConfig.endOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Sodalite"), 6, 3, 10, 250));

View file

@ -0,0 +1,54 @@
package techreborn.world;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.fml.common.IWorldGenerator;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import techreborn.init.ModBlocks;
import techreborn.world.veins.VeinGenerator;
import java.util.Random;
public enum VeinWorldGenerator implements IWorldGenerator {
INSTANCE;
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
if(random.nextInt(2) == 0) {
VeinGenerator.generateRandomVein(random, chunkX, chunkZ, world);
}
}
private static Pair<Float, IBlockState> additional(float chance, String name) {
return ImmutablePair.of(chance, ModBlocks.ore.getBlockStateFromName(name));
}
private static Pair<Float, IBlockState> primary(String name) {
return ImmutablePair.of(1.00f, ModBlocks.ore.getBlockStateFromName(name));
}
private static Pair<Float, IBlockState> primary(Block block) {
return ImmutablePair.of(1.00f, block.getDefaultState());
}
private static void registerOverworldVein(float chance, float avrSize, int minHeight, int maxHeight, Pair<Float, IBlockState>... varargs) {
VeinGenerator.registerVein(0, chance, avrSize, minHeight, maxHeight, varargs);
}
public static void registerTRVeins() {
registerOverworldVein(0.83f, 1.5f, 30, 120, primary("copper"));
registerOverworldVein(0.80f, 1.3f, 30, 100, primary("tin"));
registerOverworldVein(0.30f, 1.2f, 1, 60, primary("galena"), additional(0.3f, "lead"), additional(0.2f, "silver"));
registerOverworldVein(0.40f, 2.0f, 1, 35, primary(Blocks.REDSTONE_ORE), additional(0.3f, "ruby"));
registerOverworldVein(0.30f, 0.7f, 1, 60, primary(Blocks.LAPIS_ORE), additional(0.3f, "sapphire"));
}
}

View file

@ -0,0 +1,127 @@
package techreborn.world.veins;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider;
import org.apache.commons.lang3.tuple.Pair;
import techreborn.utils.OreDictUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class VeinGenerator {
public static final int BASE_VEIN_SIZE_Y = 38;
public static final int BASE_VEIN_SIZE_WIDTH = 26;
public static final int BASE_VEIN_SIZE_DEPTH = 14;
public static final int VEIN_DENSITY = 3;
private static final HashMap<Integer, ArrayList<VeinInfo>> dimensionVeins = new HashMap<>();
private static void registerVeinInternal(int dimension, VeinInfo veinInfo) {
if(!dimensionVeins.containsKey(dimension))
dimensionVeins.put(dimension, new ArrayList<>());
dimensionVeins.get(dimension).add(veinInfo);
}
public static void registerVein(int dimension, float chance, float minSize, float maxSize, int minHeight, int maxHeight, Map<Integer, IBlockState> blocks) {
registerVeinInternal(dimension, new VeinInfo(minSize, maxSize, minHeight, maxHeight, (int) (chance * 100), blocks));
}
public static void registerVein(int dimension, float chance, float averageSize, int minHeight, int maxHeight, Pair<Float, IBlockState>... varargs) {
HashMap<Integer, IBlockState> veinBlocks = new HashMap<>();
for(Pair<Float, IBlockState> block : varargs) veinBlocks.put((int) (block.getKey() * 100), block.getValue());
registerVein(dimension, chance, averageSize - 0.5f, averageSize + 0.5f, minHeight, maxHeight, veinBlocks);
}
public static void generateRandomVein(Random random, int chunkX, int chunkZ, World world) {
int dimension = world.provider.getDimension();
if(dimensionVeins.containsKey(dimension)) {
ArrayList<VeinInfo> veins = dimensionVeins.get(dimension);
VeinInfo randomVein = getRandomVein(veins, random);
if(randomVein != null) {
VeinGenerator.generateVein(world, chunkX, chunkZ, random, randomVein);
}
}
}
public static boolean generateVein(World world, int chunkX, int chunkZ, Random random, VeinInfo veinInfo) {
float veinSize = veinInfo.getRandomSize(random);
boolean invertXZ = random.nextBoolean();
int veinSizeX = invertXZ ? BASE_VEIN_SIZE_DEPTH : BASE_VEIN_SIZE_WIDTH;
int veinStartX = chunkX * 16 + random.nextInt(16);
int veinSizeZ = invertXZ ? BASE_VEIN_SIZE_DEPTH : BASE_VEIN_SIZE_WIDTH;
int veinStartZ = chunkZ * 16 + random.nextInt(16);
int veinMaxY = world.getTopSolidOrLiquidBlock(new BlockPos(veinStartX, 1, veinStartZ)).getY();
int veinSizeY = (int) (BASE_VEIN_SIZE_Y * veinSize);
int veinStartY = veinInfo.getRandomY(random, veinSizeY, veinMaxY);
if(isStone(world, new BlockPos(veinStartX, veinStartY, veinStartZ))) {
for(int veinX = 0; veinX < veinSizeX; veinX++) {
for(int veinZ = 0; veinZ < veinSizeZ; veinZ++) {
for(int veinY = 0; veinY < veinSizeY; veinY++) {
BlockPos veinBlockPos = new BlockPos(
veinStartX + veinX,
veinStartY + veinY,
veinStartZ + veinZ);
if(random.nextInt(VEIN_DENSITY) == 0 && isStone(world, veinBlockPos))
world.setBlockState(veinBlockPos, getOreBlock(veinInfo, random));
}
}
}
return true;
}
return false;
}
public static IBlockState getOreBlock(VeinInfo veinInfo, Random random) {
Map<Integer, IBlockState> veinBlocks = veinInfo.getVeinBlocks();
HashMap<Integer, IBlockState> clamped = new HashMap<>();
int maxValue = 0;
for(Map.Entry<Integer, IBlockState> entry : veinBlocks.entrySet()) {
maxValue += entry.getKey();
clamped.put(maxValue, entry.getValue());
}
int randomValue = random.nextInt(maxValue);
for(Map.Entry<Integer, IBlockState> entry : clamped.entrySet()) {
if(entry.getKey() > randomValue) return entry.getValue();
}
return Blocks.DIAMOND_BLOCK.getDefaultState();
}
private static VeinInfo getRandomVein(ArrayList<VeinInfo> veins, Random random) {
if(veins.isEmpty())
return null;
HashMap<Integer, VeinInfo> clamped = new HashMap<>();
int maxValue = 0;
for(VeinInfo veinInfo : veins) {
maxValue += veinInfo.getChance();
clamped.put(maxValue, veinInfo);
}
int randomValue = random.nextInt(maxValue);
for(Map.Entry<Integer, VeinInfo> entry : clamped.entrySet()) {
if(entry.getKey() > randomValue)
return entry.getValue();
}
return null;
}
public static boolean isStone(World world, BlockPos blockPos) {
IBlockState block = world.getBlockState(blockPos);
return block.getBlock() == Blocks.STONE || OreDictUtils.isOre(block, "stone");
}
}

View file

@ -0,0 +1,72 @@
package techreborn.world.veins;
import com.google.common.collect.ImmutableMap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import techreborn.blocks.BlockOre;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class VeinInfo {
private final float minSize, maxSize;
private final int minHeight, maxHeight;
private final int chance;
private final ImmutableMap<Integer, IBlockState> veinBlocks;
public VeinInfo(float minSize, float maxSize, int minHeight, int maxHeight, int chance, Map<Integer, IBlockState> veinBlocks) {
this.minSize = minSize;
this.maxSize = maxSize;
this.minHeight = minHeight;
this.maxHeight = maxHeight;
this.chance = chance;
this.veinBlocks = ImmutableMap.copyOf(veinBlocks);
}
public float getMinSize() {
return minSize;
}
public float getMaxSize() {
return maxSize;
}
public float getRandomSize(Random random) {
return minSize + random.nextFloat() * maxSize;
}
public int getMinHeight() {
return minHeight;
}
public int getMaxHeight() {
return maxHeight;
}
public int getRandomY(Random random, int boxHeight, int groundHeight) {
int maxValue = groundHeight > maxHeight ? maxHeight : groundHeight;
int randomY = (int) (minHeight + random.nextFloat() * maxValue);
if(randomY + boxHeight > maxValue) {
return randomY - (boxHeight - (maxValue - randomY));
} else if(randomY - boxHeight < minHeight) {
return randomY + (boxHeight - (randomY - minHeight));
}
return randomY;
}
public int getChance() {
return chance;
}
public boolean shouldGenerate(Random random) {
return chance >= random.nextInt(100);
}
public ImmutableMap<Integer, IBlockState> getVeinBlocks() {
return veinBlocks;
}
}