ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/event/WorldDecorationEvent.java

103 lines
6 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("WorldDecorationEvent.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-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.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntListValues;
2016-01-05 04:47:35 +01:00
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;
2015-05-20 22:39:43 +02:00
import net.minecraft.block.material.Material;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
2016-05-19 20:05:12 +02:00
import net.minecraft.world.biome.BiomeOcean;
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)){
if(Util.arrayContains(ConfigIntListValues.PLANT_DIMENSION_BLACKLIST.getValue(), event.getWorld().provider.getDimension()) < 0){
this.generateRice(event);
2016-04-20 21:39:03 +02:00
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()){
2016-04-20 21:39:03 +02:00
if(event.getRand().nextInt(300) == 0){
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
2015-05-20 22:39:43 +02:00
2016-05-19 20:05:12 +02:00
if(event.getWorld().getBiomeGenForCoords(randomPos) instanceof BiomeOcean){
if(randomPos.getY() >= 25 && randomPos.getY() <= 45){
2016-05-19 20:05:12 +02:00
if(event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER){
2016-04-20 21:39:03 +02:00
if(PosUtil.getMaterial(PosUtil.offset(randomPos, 0, -1, 0), event.getWorld()).isSolid()){
PosUtil.setBlock(randomPos, event.getWorld(), InitBlocks.blockTreasureChest, event.getRand().nextInt(4), 2);
}
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++){
2016-04-20 21:39:03 +02:00
if(event.getRand().nextInt(50) == 0){
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(PosUtil.getMaterial(randomPos, event.getWorld()) == Material.WATER){
ArrayList<Material> blocksAroundBottom = WorldUtil.getMaterialsAround(event.getWorld(), randomPos);
BlockPos posToGenAt = PosUtil.offset(randomPos, 0, 1, 0);
2016-04-20 21:39:03 +02:00
ArrayList<Material> blocksAroundTop = WorldUtil.getMaterialsAround(event.getWorld(), posToGenAt);
if(blocksAroundBottom.contains(Material.GRASS) || blocksAroundBottom.contains(Material.GROUND) || blocksAroundBottom.contains(Material.ROCK) || blocksAroundBottom.contains(Material.SAND)){
if(!blocksAroundTop.contains(Material.WATER) && PosUtil.getMaterial(posToGenAt, event.getWorld()) == Material.AIR){
PosUtil.setBlock(posToGenAt, event.getWorld(), 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++){
2016-04-20 21:39:03 +02:00
if(event.getRand().nextInt(400) == 0){
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
2015-10-03 10:19:40 +02:00
2016-04-20 21:39:03 +02:00
if(PosUtil.getMaterial(PosUtil.offset(randomPos, 0, -1, 0), event.getWorld()) == blockBelow){
if(plant.canPlaceBlockAt(event.getWorld(), randomPos) && event.getWorld().isAirBlock(randomPos)){
PosUtil.setBlock(randomPos, event.getWorld(), plant, meta, 2);
2015-11-19 18:37:11 +01:00
}
2015-10-03 10:19:40 +02:00
}
}
}
}
}
2015-05-20 22:39:43 +02:00
}