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;
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOakGenerator;
|
2020-01-29 01:34:58 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
|
|
|
import de.ellpeck.naturesaura.reg.ICustomBlockState;
|
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;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.level.ILevel;
|
|
|
|
import net.minecraft.level.Level;
|
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;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraftforge.event.level.SaplingGrowTreeEvent;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2018-11-14 19:14:03 +01:00
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2020-01-29 01:34:58 +01:00
|
|
|
public class BlockOakGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
|
2018-11-14 19:14:03 +01:00
|
|
|
|
|
|
|
public BlockOakGenerator() {
|
2021-12-04 15:40:09 +01:00
|
|
|
super("oak_generator", BlockEntityOakGenerator::new, Properties.create(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) {
|
2021-12-04 15:40:09 +01:00
|
|
|
ILevel level = event.getLevel();
|
2018-11-14 19:14:03 +01:00
|
|
|
BlockPos pos = event.getPos();
|
2021-12-04 15:40:09 +01:00
|
|
|
if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel(level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)
|
|
|
|
&& level.getBlockState(pos).getBlock() instanceof SaplingBlock) {
|
2021-12-04 19:17:21 +01:00
|
|
|
Helper.getBlockEntitiesInArea(level, pos, 10, tile -> {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!(tile instanceof BlockEntityOakGenerator))
|
2018-11-14 19:14:03 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Random rand = event.getRand();
|
|
|
|
if (rand.nextInt(10) == 0)
|
2021-12-04 15:40:09 +01:00
|
|
|
((BlockEntityOakGenerator) tile).scheduledBigTrees.add(pos);
|
2018-11-14 19:14:03 +01:00
|
|
|
|
|
|
|
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)
|
2021-12-04 15:40:09 +01:00
|
|
|
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
|
2019-01-27 13:57:34 +01:00
|
|
|
return new AxisAlignedBB(pos).grow(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2021-12-04 15:40:09 +01:00
|
|
|
public int getVisualizationColor(Level level, BlockPos pos) {
|
2019-01-27 13:57:34 +01:00
|
|
|
return 0x2e7a11;
|
|
|
|
}
|
2020-01-29 01:34:58 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomBlockState(BlockStateGenerator generator) {
|
|
|
|
generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(),
|
|
|
|
generator.modLoc("block/" + this.getBaseName()),
|
|
|
|
generator.modLoc("block/" + this.getBaseName() + "_bottom"),
|
|
|
|
generator.modLoc("block/" + this.getBaseName() + "_top")));
|
|
|
|
}
|
2018-11-14 19:14:03 +01:00
|
|
|
}
|