Skip to content

Commit

Permalink
Added generation of the 'monster_egg:97' block in over world
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Sep 24, 2024
1 parent 457ec28 commit a8bc7e5
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.imesense.dynamicspawncontrol.gameplay.worldgenerator;

import net.minecraft.block.Block;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
import org.imesense.dynamicspawncontrol.debug.CodeGenericUtils;
import org.imesense.dynamicspawncontrol.technical.configs.ConfigWorldGenerator;

import java.util.Objects;
import java.util.Random;

/**
*
* OldSerpskiStalker:
* <a href="https://forum.mcmodding.ru/threads/1-12-2-generacija.21375/">...</a>
*/
public final class BlockMonsterEgg implements IWorldGenerator
{
/**
*
*/
private final WorldGenerator CLASS_MONSTER_EGG_GENERATOR;

/**
*
*/
public BlockMonsterEgg()
{
CodeGenericUtils.printInitClassToLog(BlockMonsterEgg.class);

CLASS_MONSTER_EGG_GENERATOR = new WorldGenMinable(
Objects.requireNonNull(Block.getBlockFromName("monster_egg")).getDefaultState(), 5);
}

/**
*
* @param gen
* @param world
* @param rand
* @param chunkX
* @param chunkZ
* @param chance
* @param minHeight
* @param maxHeight
*/
private void run(WorldGenerator gen, World world, Random rand, int chunkX, int chunkZ, int chance, int minHeight, int maxHeight)
{
int heightDiff = maxHeight - minHeight + 1;

for (int i = 0; i < chance; i++)
{
int x = chunkX * 16 + rand.nextInt(16);
int y = minHeight + rand.nextInt(heightDiff);
int z = chunkZ * 16 + rand.nextInt(16);

x += rand.nextInt(10) - 6 / 2;
z += rand.nextInt(10) - 6 / 2;

gen.generate(world, rand, new BlockPos(x, y, z));
}
}

/**
*
* @param random
* @param chunkX
* @param chunkZ
* @param world
* @param chunkGenerator
* @param chunkProvider
*/
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
{
switch (world.provider.getDimension())
{
case 0:
{
run(
CLASS_MONSTER_EGG_GENERATOR, world, random, chunkX, chunkZ,
ConfigWorldGenerator.settingsGenerationBlockNetherRack.BlockNetherRackChanceSpawn,
ConfigWorldGenerator.settingsGenerationBlockNetherRack.GetBlockNetherRackMinHeight,
ConfigWorldGenerator.settingsGenerationBlockNetherRack.GetBlockNetherRackMaxHeight
);
break;
}

case 1: case -1: default: break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

/**
*
* OldSerpskiStalker:
* <a href="https://forum.mcmodding.ru/threads/1-12-2-generacija.21375/">...</a>
*/
public final class MossyCobblestone implements IWorldGenerator
public final class BlockMossyCobblestone implements IWorldGenerator
{
/**
*
Expand All @@ -27,12 +29,12 @@ public final class MossyCobblestone implements IWorldGenerator
/**
*
*/
public MossyCobblestone()
public BlockMossyCobblestone()
{
CodeGenericUtils.printInitClassToLog(MossyCobblestone.class);
CodeGenericUtils.printInitClassToLog(BlockMossyCobblestone.class);

CLASS_MOSSY_COBBLESTONE_GENERATOR = new WorldGenMinable(
Objects.requireNonNull(Block.getBlockFromName("mossy_cobblestone")).getDefaultState(), 9);
Objects.requireNonNull(Block.getBlockFromName("mossy_cobblestone")).getDefaultState(), 5);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
import org.imesense.dynamicspawncontrol.debug.CodeGenericUtils;
import org.imesense.dynamicspawncontrol.gameplay.gameworld.WorldTime;
import org.imesense.dynamicspawncontrol.technical.configs.ConfigWorldGenerator;

import java.util.Objects;
Expand All @@ -20,7 +19,7 @@
* OldSerpskiStalker:
* <a href="https://forum.mcmodding.ru/threads/1-12-2-generacija.21375/">...</a>
*/
public final class NetherRackGenerator implements IWorldGenerator
public final class BlockNetherRack implements IWorldGenerator
{
/**
*
Expand All @@ -30,12 +29,12 @@ public final class NetherRackGenerator implements IWorldGenerator
/**
*
*/
public NetherRackGenerator()
public BlockNetherRack()
{
CodeGenericUtils.printInitClassToLog(NetherRackGenerator.class);
CodeGenericUtils.printInitClassToLog(BlockNetherRack.class);

CLASS_NETHER_RACK_GENERATOR = new WorldGenMinable(
Objects.requireNonNull(Block.getBlockFromName("netherrack")).getDefaultState(), 9);
Objects.requireNonNull(Block.getBlockFromName("netherrack")).getDefaultState(), 5);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.imesense.dynamicspawncontrol.debug.CodeGenericUtils;
import org.imesense.dynamicspawncontrol.gameplay.worldgenerator.NetherRackGenerator;
import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;
import org.imesense.dynamicspawncontrol.technical.proxy.ClientProxy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ public static final class settingsGenerationBlockMossyCobblestone
public static int GetBlockMossyCobblestoneMaxHeight = 45;
}

/**
*
*/
public static final class settingsGenerationBlockMonsterEgg
{
/**
*
*/
public static int BlockMonsterEggChanceSpawn = 10;

/**
*
*/
public static int GetBlockMonsterEggMinHeight = 7;

/**
*
*/
public static int GetBlockMonsterEggMaxHeight = 40;
}

/**
*
*/
Expand Down Expand Up @@ -96,10 +117,12 @@ public void init(FMLPreInitializationEvent event)
@Override
public void readProperties(Configuration configuration)
{
//-' ***************************************************************************************************

settingsGenerationBlockNetherRack.BlockNetherRackChanceSpawn = this.getConfigValueI(
configuration,
"Ore Netherrack Chance Spawn",
"ore_generator_over_world",
"config_netherrack",
settingsGenerationBlockNetherRack.BlockNetherRackChanceSpawn,
1,
100,
Expand All @@ -109,7 +132,7 @@ public void readProperties(Configuration configuration)
settingsGenerationBlockNetherRack.GetBlockNetherRackMinHeight = this.getConfigValueI(
configuration,
"Ore Netherrack Min Height",
"ore_generator_over_world",
"config_netherrack",
settingsGenerationBlockNetherRack.GetBlockNetherRackMinHeight,
2,
10,
Expand All @@ -119,17 +142,19 @@ public void readProperties(Configuration configuration)
settingsGenerationBlockNetherRack.GetBlockNetherRackMaxHeight = this.getConfigValueI(
configuration,
"Ore Netherrack Max Height",
"ore_generator_over_world",
"config_netherrack",
settingsGenerationBlockNetherRack.GetBlockNetherRackMaxHeight,
10,
20,
"The maximal height of 'netherrack' appearing"
);

//-' ***************************************************************************************************

settingsGenerationBlockMossyCobblestone.BlockMossyCobblestoneChanceSpawn = this.getConfigValueI(
configuration,
"Ore Mossy Cobblestone Chance Spawn",
"ore_generator_over_world",
"config_mossy_cobblestone",
settingsGenerationBlockMossyCobblestone.BlockMossyCobblestoneChanceSpawn,
1,
100,
Expand All @@ -139,7 +164,7 @@ public void readProperties(Configuration configuration)
settingsGenerationBlockMossyCobblestone.GetBlockMossyCobblestoneMinHeight = this.getConfigValueI(
configuration,
"Ore Mossy Cobblestone Min Height",
"ore_generator_over_world",
"config_mossy_cobblestone",
settingsGenerationBlockMossyCobblestone.GetBlockMossyCobblestoneMinHeight,
5,
25,
Expand All @@ -149,12 +174,44 @@ public void readProperties(Configuration configuration)
settingsGenerationBlockMossyCobblestone.GetBlockMossyCobblestoneMaxHeight = this.getConfigValueI(
configuration,
"Ore Mossy Cobblestone Max Height",
"ore_generator_over_world",
"config_mossy_cobblestone",
settingsGenerationBlockMossyCobblestone.GetBlockMossyCobblestoneMaxHeight,
25,
65,
"The maximal height of 'mossy_cobblestone' appearing"
);

//-' ***************************************************************************************************

settingsGenerationBlockMonsterEgg.BlockMonsterEggChanceSpawn = this.getConfigValueI(
configuration,
"Ore Monster Egg Chance Spawn",
"config_monster_egg",
settingsGenerationBlockMonsterEgg.BlockMonsterEggChanceSpawn,
1,
100,
"The chance of 'monster_egg' appearing"
);

settingsGenerationBlockMonsterEgg.GetBlockMonsterEggMinHeight = this.getConfigValueI(
configuration,
"Ore Monster Egg Min Height",
"config_monster_egg",
settingsGenerationBlockMonsterEgg.GetBlockMonsterEggMinHeight,
5,
25,
"The minimal height of 'monster_egg' appearing"
);

settingsGenerationBlockMonsterEgg.GetBlockMonsterEggMaxHeight = this.getConfigValueI(
configuration,
"Ore Monster Egg Max Height",
"config_monster_egg",
settingsGenerationBlockMonsterEgg.GetBlockMonsterEggMaxHeight,
25,
65,
"The maximal height of 'monster_egg' appearing"
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.imesense.dynamicspawncontrol.technical.initializer;

import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
Expand All @@ -18,8 +17,9 @@ public final class RegisterOreGenerators
*/
private static final Class<?>[] ORE_GENERATOR_CLASSES =
{
NetherRackGenerator.class,
MossyCobblestone.class
BlockNetherRack.class,
BlockMossyCobblestone.class,
BlockMonsterEgg.class
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import org.imesense.dynamicspawncontrol.gameplay.worldgenerator.MossyCobblestone;
import org.imesense.dynamicspawncontrol.gameplay.worldgenerator.NetherRackGenerator;
import org.imesense.dynamicspawncontrol.technical.initializer.RegisterConfigClasses;
import org.imesense.dynamicspawncontrol.debug.CodeGenericUtils;
import org.imesense.dynamicspawncontrol.technical.initializer.RegisterOreGenerators;
Expand Down

0 comments on commit a8bc7e5

Please sign in to comment.