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
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.event;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-08 13:31:58 +01:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheWildPlants;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
|
2016-01-08 13:31:58 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2015-06-06 01:25:53 +02:00
|
|
|
import net.minecraft.block.Block;
|
2016-01-07 23:42:42 +01:00
|
|
|
import net.minecraft.block.BlockBush;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
2016-01-08 13:31:58 +01:00
|
|
|
import net.minecraft.util.BlockPos;
|
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;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
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)){
|
2016-01-07 23:42:42 +01:00
|
|
|
if(Util.arrayContains(ConfigValues.plantDimensionBlacklist, event.world.provider.getDimensionId()) < 0){
|
2015-11-20 20:52:03 +01:00
|
|
|
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-11-28 19:02:01 +01:00
|
|
|
if(event.rand.nextInt(300) == 0){
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos randomPos = new BlockPos(event.pos.getX()+event.rand.nextInt(16)+8, 0, event.pos.getZ()+event.rand.nextInt(16)+8);
|
|
|
|
randomPos = event.world.getTopSolidOrLiquidBlock(randomPos);
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-07 23:42:42 +01:00
|
|
|
if(event.world.getBiomeGenForCoords(randomPos) instanceof BiomeGenOcean){
|
|
|
|
if(randomPos.getY() >= 25 && randomPos.getY() <= 45){
|
2016-01-08 13:31:58 +01:00
|
|
|
if(PosUtil.getBlock(randomPos, event.world).getMaterial() == Material.water){
|
|
|
|
if(PosUtil.getMaterial(PosUtil.offset(randomPos, 0, -1, 0), event.world).isSolid()){
|
|
|
|
PosUtil.setBlock(randomPos, event.world, 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-11-28 19:02:01 +01:00
|
|
|
if(event.rand.nextInt(50) == 0){
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos randomPos = new BlockPos(event.pos.getX()+event.rand.nextInt(16)+8, 0, event.pos.getZ()+event.rand.nextInt(16)+8);
|
|
|
|
randomPos = event.world.getTopSolidOrLiquidBlock(randomPos);
|
2015-07-10 13:08:20 +02:00
|
|
|
|
2016-01-08 13:31:58 +01:00
|
|
|
if(PosUtil.getMaterial(randomPos, event.world) == Material.water){
|
2016-01-07 23:42:42 +01:00
|
|
|
ArrayList<Material> blocksAroundBottom = WorldUtil.getMaterialsAround(event.world, randomPos);
|
2016-01-08 13:31:58 +01:00
|
|
|
ArrayList<Material> blocksAroundTop = WorldUtil.getMaterialsAround(event.world, PosUtil.offset(randomPos, 0, 1, 0));
|
2015-07-10 13:08:20 +02:00
|
|
|
if(blocksAroundBottom.contains(Material.grass) || blocksAroundBottom.contains(Material.ground) || blocksAroundBottom.contains(Material.rock) || blocksAroundBottom.contains(Material.sand)){
|
2016-01-08 13:31:58 +01:00
|
|
|
if(!blocksAroundTop.contains(Material.water) && PosUtil.getMaterial(randomPos, event.world) == Material.air){
|
|
|
|
PosUtil.setBlock(PosUtil.offset(randomPos, 0, 1, 0), event.world, InitBlocks.blockWildPlant, TheWildPlants.RICE.ordinal(), 2);
|
2015-07-10 13:08:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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++){
|
2015-11-28 19:02:01 +01:00
|
|
|
if(event.rand.nextInt(400) == 0){
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos randomPos = new BlockPos(event.pos.getX()+event.rand.nextInt(16)+8, 0, event.pos.getZ()+event.rand.nextInt(16)+8);
|
|
|
|
randomPos = event.world.getTopSolidOrLiquidBlock(randomPos);
|
2015-10-03 10:19:40 +02:00
|
|
|
|
2016-01-08 13:31:58 +01:00
|
|
|
if(PosUtil.getMaterial(randomPos, event.world) == blockBelow){
|
|
|
|
BlockPos top = PosUtil.offset(randomPos, 0, 1, 0);
|
|
|
|
PosUtil.setBlock(top, event.world, plant, meta, 2);
|
|
|
|
if(plant instanceof BlockBush && !((BlockBush)plant).canBlockStay(event.world, top, event.world.getBlockState(top))){
|
2016-01-07 23:42:42 +01:00
|
|
|
event.world.setBlockToAir(top);
|
2015-11-19 18:37:11 +01:00
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|