-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CustomFireball and NetherRackGenerator
- Loading branch information
1 parent
f6c204f
commit a783203
Showing
6 changed files
with
308 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/gameplay/items/CustomFireball.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...in/java/org/imesense/dynamicspawncontrol/gameplay/worldgenerator/NetherRackGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
.../main/java/org/imesense/dynamicspawncontrol/technical/configs/SettingsWorldGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters