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-02-16 21:31:37 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
2019-01-28 15:43:21 +01:00
|
|
|
import de.ellpeck.naturesaura.api.render.IVisualizable;
|
2020-01-21 23:02:39 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
|
2018-11-14 19:14:03 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityOakGenerator;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.SaplingBlock;
|
2018-11-14 19:14:03 +01:00
|
|
|
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;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.world.IWorld;
|
2018-11-14 19:14:03 +01:00
|
|
|
import net.minecraft.world.World;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.world.SaplingGrowTreeEvent;
|
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2018-11-14 19:14:03 +01:00
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2019-01-28 15:43:21 +01:00
|
|
|
public class BlockOakGenerator extends BlockContainerImpl implements IVisualizable {
|
2018-11-14 19:14:03 +01:00
|
|
|
|
|
|
|
public BlockOakGenerator() {
|
2020-01-21 23:02:39 +01:00
|
|
|
super("oak_generator", ModTileEntities.OAK_GENERATOR, ModBlocks.prop(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD));
|
2018-11-14 19:14:03 +01:00
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
2018-11-14 19:14:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onTreeGrow(SaplingGrowTreeEvent event) {
|
2020-01-21 21:04:44 +01:00
|
|
|
IWorld world = event.getWorld();
|
2018-11-14 19:14:03 +01:00
|
|
|
BlockPos pos = event.getPos();
|
2020-01-21 21:04:44 +01:00
|
|
|
if (!world.isRemote() && IAuraType.forWorld(world).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)
|
2019-10-20 22:30:49 +02:00
|
|
|
&& world.getBlockState(pos).getBlock() instanceof SaplingBlock) {
|
2018-11-14 19:14:03 +01:00
|
|
|
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
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-01-27 13:57:34 +01:00
|
|
|
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
|
|
|
|
return new AxisAlignedBB(pos).grow(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-01-27 13:57:34 +01:00
|
|
|
public int getVisualizationColor(World world, BlockPos pos) {
|
|
|
|
return 0x2e7a11;
|
|
|
|
}
|
2018-11-14 19:14:03 +01:00
|
|
|
}
|