2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("WorldDecorationEvent.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
package ellpeck.actuallyadditions.event;
|
|
|
|
|
2015-07-10 13:08:20 +02:00
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
2015-05-20 22:39:43 +02:00
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
2015-06-28 03:12:32 +02:00
|
|
|
import ellpeck.actuallyadditions.blocks.metalists.TheWildPlants;
|
2015-11-20 20:52:03 +01:00
|
|
|
import ellpeck.actuallyadditions.config.ConfigValues;
|
2015-05-20 22:39:43 +02:00
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
|
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-11-20 20:52:03 +01:00
|
|
|
import ellpeck.actuallyadditions.util.Util;
|
2015-06-28 03:12:32 +02:00
|
|
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
2015-06-06 01:25:53 +02:00
|
|
|
import net.minecraft.block.Block;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
2015-07-10 17:26:35 +02:00
|
|
|
import net.minecraft.world.biome.BiomeGenOcean;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class WorldDecorationEvent{
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2015-07-10 13:08:20 +02:00
|
|
|
public void onWorldDecoration(DecorateBiomeEvent.Decorate event){
|
|
|
|
if((event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT)){
|
2015-11-20 20:52:03 +01:00
|
|
|
if(Util.arrayContains(ConfigValues.plantDimensionBlacklist, event.world.provider.dimensionId) < 0){
|
|
|
|
this.generateRice(event);
|
|
|
|
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.CANOLA.ordinal(), ConfigIntValues.CANOLA_AMOUNT.getValue(), ConfigBoolValues.DO_CANOLA_GEN.isEnabled(), Material.grass, event);
|
|
|
|
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.FLAX.ordinal(), ConfigIntValues.FLAX_AMOUNT.getValue(), ConfigBoolValues.DO_FLAX_GEN.isEnabled(), Material.grass, event);
|
|
|
|
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.COFFEE.ordinal(), ConfigIntValues.COFFEE_AMOUNT.getValue(), ConfigBoolValues.DO_COFFEE_GEN.isEnabled(), Material.grass, event);
|
|
|
|
this.genPlantNormally(InitBlocks.blockBlackLotus, 0, ConfigIntValues.BLACK_LOTUS_AMOUNT.getValue(), ConfigBoolValues.DO_LOTUS_GEN.isEnabled(), Material.grass, event);
|
|
|
|
}
|
2015-07-10 13:08:20 +02:00
|
|
|
|
|
|
|
//Generate Treasure Chests
|
|
|
|
if(ConfigBoolValues.DO_TREASURE_CHEST_GEN.isEnabled()){
|
2015-07-12 05:16:26 +02:00
|
|
|
if(event.rand.nextInt(ConfigIntValues.TREASURE_CHEST_CHANCE.getValue()) == 0){
|
2015-05-20 22:39:43 +02:00
|
|
|
int genX = event.chunkX+event.rand.nextInt(16)+8;
|
|
|
|
int genZ = event.chunkZ+event.rand.nextInt(16)+8;
|
|
|
|
int genY = event.world.getTopSolidOrLiquidBlock(genX, genZ);
|
|
|
|
|
2015-07-10 17:26:35 +02:00
|
|
|
if(event.world.getBiomeGenForCoords(genX, genZ) instanceof BiomeGenOcean){
|
|
|
|
if(genY >= ConfigIntValues.TREASURE_CHEST_MIN_HEIGHT.getValue() && genY <= ConfigIntValues.TREASURE_CHEST_MAX_HEIGHT.getValue()){
|
|
|
|
if(event.world.getBlock(genX, genY, genZ).getMaterial() == Material.water){
|
|
|
|
if(event.world.getBlock(genX, genY-1, genZ).getMaterial().isSolid()){
|
2015-07-12 05:16:26 +02:00
|
|
|
event.world.setBlock(genX, genY, genZ, InitBlocks.blockTreasureChest, event.rand.nextInt(4), 2);
|
2015-07-10 17:26:35 +02:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
|
|
|
|
2015-07-10 13:08:20 +02:00
|
|
|
private void generateRice(DecorateBiomeEvent event){
|
|
|
|
if(ConfigBoolValues.DO_RICE_GEN.isEnabled()){
|
|
|
|
for(int i = 0; i < ConfigIntValues.RICE_AMOUNT.getValue(); i++){
|
2015-07-12 05:16:26 +02:00
|
|
|
if(event.rand.nextInt(ConfigIntValues.RICE_CHANCE.getValue()) == 0){
|
2015-07-10 13:08:20 +02:00
|
|
|
int genX = event.chunkX+event.rand.nextInt(16)+8;
|
|
|
|
int genZ = event.chunkZ+event.rand.nextInt(16)+8;
|
|
|
|
int genY = event.world.getTopSolidOrLiquidBlock(genX, genZ);
|
|
|
|
|
|
|
|
if(event.world.getBlock(genX, genY, genZ).getMaterial() == Material.water){
|
|
|
|
ArrayList<Material> blocksAroundBottom = WorldUtil.getMaterialsAround(event.world, genX, genY, genZ);
|
|
|
|
ArrayList<Material> blocksAroundTop = WorldUtil.getMaterialsAround(event.world, genX, genY+1, genZ);
|
|
|
|
if(blocksAroundBottom.contains(Material.grass) || blocksAroundBottom.contains(Material.ground) || blocksAroundBottom.contains(Material.rock) || blocksAroundBottom.contains(Material.sand)){
|
|
|
|
if(!blocksAroundTop.contains(Material.water) && event.world.getBlock(genX, genY+1, genZ).getMaterial() == Material.air){
|
|
|
|
event.world.setBlock(genX, genY+1, genZ, InitBlocks.blockWildPlant, TheWildPlants.RICE.ordinal(), 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
|
|
|
|
private void genPlantNormally(Block plant, int meta, int amount, boolean doIt, Material blockBelow, DecorateBiomeEvent event){
|
|
|
|
if(doIt){
|
|
|
|
for(int i = 0; i < amount; i++){
|
|
|
|
if(event.rand.nextInt(ConfigIntValues.NORMAL_PLANT_CHANCE.getValue()) == 0){
|
|
|
|
int genX = event.chunkX+event.rand.nextInt(16)+8;
|
|
|
|
int genZ = event.chunkZ+event.rand.nextInt(16)+8;
|
|
|
|
int genY = event.world.getTopSolidOrLiquidBlock(genX, genZ)-1;
|
|
|
|
|
2015-11-19 18:37:11 +01:00
|
|
|
if(event.world.getBlock(genX, genY, genZ).getMaterial() == blockBelow){
|
2015-10-03 10:19:40 +02:00
|
|
|
event.world.setBlock(genX, genY+1, genZ, plant, meta, 2);
|
2015-11-19 18:37:11 +01:00
|
|
|
if(!plant.canBlockStay(event.world, genX, genY+1, genZ)){
|
|
|
|
event.world.setBlockToAir(genX, genY+1, genZ);
|
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|