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-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.client.color.block.BlockColor;
|
|
|
|
import net.minecraft.client.color.item.ItemColor;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
|
|
|
import net.minecraft.world.level.Level;
|
2021-12-08 00:31:29 +01:00
|
|
|
import net.minecraft.world.level.block.Block;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.world.level.block.EntityBlock;
|
2021-12-08 00:31:29 +01:00
|
|
|
import net.minecraft.world.level.block.LeavesBlock;
|
|
|
|
import net.minecraft.world.level.block.SoundType;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
2021-12-08 00:31:29 +01:00
|
|
|
import net.minecraft.world.level.material.Material;
|
|
|
|
import net.minecraft.world.level.material.MaterialColor;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2021-12-15 14:26:42 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2018-10-13 23:46:30 +02:00
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2021-12-15 14:26:42 +01:00
|
|
|
public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorProvidingBlock, IColorProvidingItem, ICustomBlockState, EntityBlock {
|
2018-10-13 23:46:30 +02:00
|
|
|
|
|
|
|
public BlockAncientLeaves() {
|
2021-12-08 00:31:29 +01:00
|
|
|
super(Block.Properties.of(Material.LEAVES, MaterialColor.COLOR_PINK).strength(0.2F).randomTicks().noOcclusion().sound(SoundType.GRASS));
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2021-12-15 14:26:42 +01:00
|
|
|
public BlockColor 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)
|
2021-12-15 14:26:42 +01:00
|
|
|
public ItemColor 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);
|
2021-12-15 14:26:42 +01:00
|
|
|
if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.below()).isCollisionShapeFullBlock(levelIn, pos)) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var tile = levelIn.getBlockEntity(pos);
|
2021-12-04 15:40:09 +01:00
|
|
|
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) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var tile = levelIn.getBlockEntity(pos);
|
2021-12-04 15:40:09 +01:00
|
|
|
if (tile instanceof BlockEntityAncientLeaves) {
|
|
|
|
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) {
|
2021-12-15 14:26:42 +01:00
|
|
|
levelIn.setBlockAndUpdate(pos, ModBlocks.DECAYED_LEAVES.defaultBlockState());
|
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
|
2021-12-15 14:26:42 +01:00
|
|
|
public boolean isRandomlyTicking(BlockState state) {
|
2020-05-12 17:35:32 +02:00
|
|
|
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())));
|
|
|
|
}
|
2021-12-15 14:26:42 +01:00
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
|
|
return new BlockEntityAncientLeaves(pos, state);
|
|
|
|
}
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|