2018-10-13 23:46:30 +02:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAncientLeaves;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
2018-10-13 23:46:30 +02:00
|
|
|
import de.ellpeck.naturesaura.reg.*;
|
2021-01-14 23:15:02 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.block.LeavesBlock;
|
|
|
|
import net.minecraft.block.SoundType;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.material.MaterialColor;
|
2018-10-13 23:46:30 +02:00
|
|
|
import net.minecraft.client.renderer.color.IBlockColor;
|
|
|
|
import net.minecraft.client.renderer.color.IItemColor;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.tileentity.BlockEntity;
|
2018-10-13 23:46:30 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.level.IBlockReader;
|
|
|
|
import net.minecraft.level.Level;
|
|
|
|
import net.minecraft.level.server.ServerLevel;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-10-13 23:46:30 +02:00
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2020-01-29 00:40:28 +01:00
|
|
|
public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorProvidingBlock, IColorProvidingItem, ICustomBlockState {
|
2018-10-13 23:46:30 +02:00
|
|
|
|
|
|
|
public BlockAncientLeaves() {
|
2020-10-17 21:13:45 +02:00
|
|
|
super(Properties.create(Material.LEAVES, MaterialColor.PINK).hardnessAndResistance(0.2F).tickRandomly().notSolid().sound(SoundType.PLANT));
|
2018-11-29 17:58:47 +01:00
|
|
|
ModRegistry.add(this);
|
2021-12-04 15:40:09 +01:00
|
|
|
ModRegistry.add(new ModTileType<>(BlockEntityAncientLeaves::new, this));
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return "ancient_leaves";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public BlockEntity createBlockEntity(BlockState state, IBlockReader level) {
|
|
|
|
return new BlockEntityAncientLeaves();
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
2020-01-24 17:05:41 +01:00
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public boolean hasBlockEntity(BlockState state) {
|
2020-01-24 17:05:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-13 23:46:30 +02:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-10-13 23:46:30 +02:00
|
|
|
public IBlockColor getBlockColor() {
|
2021-12-04 15:40:09 +01:00
|
|
|
return (state, levelIn, pos, tintIndex) -> 0xE55B97;
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-10-13 23:46:30 +02:00
|
|
|
public IItemColor getItemColor() {
|
2019-01-30 17:51:39 +01:00
|
|
|
return (stack, tintIndex) -> 0xE55B97;
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2021-12-04 15:40:09 +01:00
|
|
|
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
|
|
|
|
super.animateTick(stateIn, levelIn, pos, rand);
|
|
|
|
if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.down()).isOpaqueCube(levelIn, pos)) {
|
|
|
|
BlockEntity tile = levelIn.getBlockEntity(pos);
|
|
|
|
if (tile instanceof BlockEntityAncientLeaves) {
|
|
|
|
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() > 0) {
|
2018-11-13 00:36:47 +01:00
|
|
|
NaturesAuraAPI.instance().spawnMagicParticle(
|
2018-10-14 16:12:33 +02:00
|
|
|
pos.getX() + rand.nextDouble(), pos.getY(), pos.getZ() + rand.nextDouble(),
|
2019-01-30 17:51:39 +01:00
|
|
|
0F, 0F, 0F, 0xCC4780,
|
2018-10-14 16:12:33 +02:00
|
|
|
rand.nextFloat() * 2F + 0.5F,
|
2018-11-04 18:42:35 +01:00
|
|
|
rand.nextInt(50) + 75,
|
|
|
|
rand.nextFloat() * 0.02F + 0.002F, true, true);
|
2018-10-14 16:12:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
|
|
|
|
super.randomTick(state, levelIn, pos, random);
|
|
|
|
if (!levelIn.isClientSide) {
|
|
|
|
BlockEntity tile = levelIn.getBlockEntity(pos);
|
|
|
|
if (tile instanceof BlockEntityAncientLeaves) {
|
|
|
|
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) {
|
|
|
|
levelIn.setBlockState(pos, ModBlocks.DECAYED_LEAVES.getDefaultState());
|
2018-10-14 16:12:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 00:40:28 +01:00
|
|
|
|
2020-05-12 17:35:32 +02:00
|
|
|
@Override
|
|
|
|
public boolean ticksRandomly(BlockState state) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-29 00:40:28 +01:00
|
|
|
@Override
|
|
|
|
public void generateCustomBlockState(BlockStateGenerator generator) {
|
|
|
|
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
|
|
|
|
}
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|