Skip to content

Commit

Permalink
Add CustomFireball and NetherRackGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Sep 17, 2024
1 parent f6c204f commit a783203
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.imesense.dynamicspawncontrol.debug.events;

import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;

/**
*
*/
Expand All @@ -10,6 +12,6 @@ public final class OnEventDummy
*/
public OnEventDummy(final String nameClass)
{

Log.writeDataToLogFile(Log.TypeLog[0], nameClass);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.imesense.dynamicspawncontrol.gameplay.items;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityFireball;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
import java.util.Random;

/**
*
*/
public final class CustomFireball extends EntityFireball
{
/**
*
*/
private interface FireSpawnAction
{
/**
*
* @param world
* @param explosionPos
* @param radius
*/
void spawnFire(World world, BlockPos explosionPos, int radius);
}

/**
*
* @param worldIn
*/
public CustomFireball(World worldIn)
{
super(worldIn);
}

/**
*
* @param worldIn
* @param x
* @param y
* @param z
* @param accelX
* @param accelY
* @param accelZ
*/
public CustomFireball(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
{
super(worldIn, x, y, z, accelX, accelY, accelZ);
}

/**
*
* @param worldIn
* @param shooter
* @param accelX
* @param accelY
* @param accelZ
*/
public CustomFireball(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ)
{
super(worldIn, shooter, accelX, accelY, accelZ);
}

/**
*
* @param result
*/
@Override
protected void onImpact(@Nonnull RayTraceResult result)
{
if (!this.world.isRemote)
{
this.world.createExplosion(this.shootingEntity, this.posX, this.posY, this.posZ, 7.0f, true);

FireSpawnAction fireSpawnAction = (world, explosionPos, radius) ->
{
for (int x = -radius; x <= radius + new Random().nextInt(5); x++)
{
for (int y = -radius; y <= radius + new Random().nextInt(5); y++)
{
for (int z = -radius; z <= radius + new Random().nextInt(5); z++)
{
BlockPos blockPos = explosionPos.add(x, y, z);
double distanceSq = explosionPos.distanceSq(blockPos);

if (distanceSq <= radius * radius && world.getBlockState(blockPos).getBlock() == Blocks.AIR)
{
if (new Random().nextFloat() < 0.1f)
{
world.setBlockState(blockPos, Blocks.FIRE.getDefaultState());
}
}
}
}
}
};

fireSpawnAction.spawnFire(this.world, new BlockPos(this.posX, this.posY, this.posZ), 10);
this.setDead();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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.technical.configs.SettingsWorldGenerator;
import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;

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 NetherRackGenerator implements IWorldGenerator
{
/**
*
*/
private final WorldGenerator classGenerateBlockNetherRack;

/**
*
* @param nameClass
*/
public NetherRackGenerator(final String nameClass)
{
Log.writeDataToLogFile(Log.TypeLog[0], nameClass);

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

/**
*
* @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(
classGenerateBlockNetherRack, world, random, chunkX, chunkZ,
SettingsWorldGenerator.BlockNetherrackChanceSpawn,
SettingsWorldGenerator.GetBlockNetherrackMinHeight,
SettingsWorldGenerator.GetBlockNetherrackMaxHeight
);
break;
}

case 1: case -1: default: break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
*
*/
public class SettingsGameDebugger implements IConfig
public final class SettingsGameDebugger implements IConfig
{
/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.imesense.dynamicspawncontrol.technical.configs;

import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.imesense.dynamicspawncontrol.DynamicSpawnControl;
import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;
import org.imesense.dynamicspawncontrol.technical.proxy.ClientProxy;

import java.io.File;

/**
*
*/
public final class SettingsWorldGenerator implements IConfig
{
/**
*
*/
public static int BlockNetherrackChanceSpawn = 20;

/**
*
*/
public static int GetBlockNetherrackMinHeight = 5;

/**
*
*/
public static int GetBlockNetherrackMaxHeight = 20;

/**
*
* @param event
* @param nameClass
*/
@Override
public void init(FMLPreInitializationEvent event, final String nameClass)
{
Log.writeDataToLogFile(Log.TypeLog[0], nameClass);

ClientProxy.ConfigOreGeneratorFile = new Configuration(new File(DynamicSpawnControl.getGlobalPathToConfigs().getPath() +
File.separator + DynamicSpawnControl.STRUCT_FILES_DIRS.NAME_DIRECTORY +
File.separator + DynamicSpawnControl.STRUCT_FILES_DIRS.NAME_DIR_CONFIGS,
"ore_generator" + DynamicSpawnControl.STRUCT_FILES_EXTENSION.CONFIG_FILE_EXTENSION));

this.read();
}

/**
*
* @param configuration
*/
@Override
public void readProperties(Configuration configuration)
{
BlockNetherrackChanceSpawn =
configuration.getInt("Ore Netherrack Chance Spawn", "ore_generator_over_world", BlockNetherrackChanceSpawn, 1, 100,
"The chance of 'netherrack' appearing");

GetBlockNetherrackMinHeight =
configuration.getInt("Ore Netherrack Min Height", "ore_generator_over_world", GetBlockNetherrackMinHeight, 2, 10,
"The minimal height of 'netherrack' appearing");

GetBlockNetherrackMaxHeight =
configuration.getInt("Ore Netherrack Max Height", "ore_generator_over_world", GetBlockNetherrackMaxHeight, 10, 20,
"The maximal height of 'netherrack' appearing");
}

/**
*
*/
@Override
public void read()
{
Configuration configuration = ClientProxy.ConfigOreGeneratorFile;

try
{
configuration.load();
this.readProperties(configuration);
}
finally
{
if (configuration.hasChanged())
{
configuration.save();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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.NetherRackGenerator;
import org.imesense.dynamicspawncontrol.technical.configs.ConfigManager;

/**
Expand All @@ -28,6 +30,11 @@ public final class ClientProxy implements IProxy
*/
public static Configuration ConfigGameDebugger;

/**
*
*/
public static Configuration ConfigOreGeneratorFile;

/**
* Preinitialize modification
*
Expand All @@ -37,6 +44,8 @@ public final class ClientProxy implements IProxy
public void preInit(FMLPreInitializationEvent event)
{
ConfigManager.init(event);

GameRegistry.registerWorldGenerator(new NetherRackGenerator("NetherRackGenerator"), 3);
}

/**
Expand All @@ -59,6 +68,7 @@ public void postInit(FMLPostInitializationEvent event)
{
ConfigLogFile.save();
ConfigGameDebugger.save();
ConfigOreGeneratorFile.save();
}

/**
Expand Down

0 comments on commit a783203

Please sign in to comment.