NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/BlockOakGenerator.java

70 lines
2.4 KiB
Java
Raw Normal View History

2018-11-14 19:14:03 +01:00
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
2019-01-27 13:57:34 +01:00
import de.ellpeck.naturesaura.api.render.IVisualizableBlock;
2018-11-14 19:14:03 +01:00
import de.ellpeck.naturesaura.blocks.tiles.TileEntityOakGenerator;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
2019-01-27 13:57:34 +01:00
import net.minecraft.util.math.AxisAlignedBB;
2018-11-14 19:14:03 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.terraingen.SaplingGrowTreeEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
2019-01-27 13:57:34 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2018-11-14 19:14:03 +01:00
import java.util.Random;
2019-01-27 13:57:34 +01:00
public class BlockOakGenerator extends BlockContainerImpl implements IVisualizableBlock {
2018-11-14 19:14:03 +01:00
public BlockOakGenerator() {
super(Material.WOOD, "oak_generator", TileEntityOakGenerator.class, "oak_generator");
this.setHardness(2F);
this.setSoundType(SoundType.WOOD);
MinecraftForge.TERRAIN_GEN_BUS.register(this);
}
@SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) {
World world = event.getWorld();
BlockPos pos = event.getPos();
if (!world.isRemote && NaturesAuraAPI.TYPE_OVERWORLD.isPresentInWorld(world)
&& world.getBlockState(pos).getBlock() instanceof BlockSapling) {
Helper.getTileEntitiesInArea(world, pos, 10, tile -> {
if (!(tile instanceof TileEntityOakGenerator))
return false;
Random rand = event.getRand();
if (rand.nextInt(10) == 0)
((TileEntityOakGenerator) tile).scheduledBigTrees.add(pos);
long seed;
do {
seed = rand.nextLong();
rand.setSeed(seed);
}
while (rand.nextInt(10) == 0);
rand.setSeed(seed);
return true;
});
}
}
2019-01-27 13:57:34 +01:00
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(pos).grow(10);
}
@Override
@SideOnly(Side.CLIENT)
public int getVisualizationColor(World world, BlockPos pos) {
return 0x2e7a11;
}
2018-11-14 19:14:03 +01:00
}