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

87 lines
3.1 KiB
Java
Raw Normal View History

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;
2018-10-13 23:46:30 +02:00
import de.ellpeck.naturesaura.blocks.tiles.TileEntityAncientLeaves;
import de.ellpeck.naturesaura.reg.*;
2019-11-04 19:08:49 +01:00
import net.minecraft.block.BlockState;
2019-10-20 22:30:49 +02:00
import net.minecraft.block.LeavesBlock;
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;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
2019-11-04 19:08:49 +01:00
import net.minecraft.world.IBlockReader;
2018-10-13 23:46:30 +02: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;
2018-10-13 23:46:30 +02:00
import javax.annotation.Nullable;
import java.util.Random;
2019-10-20 22:30:49 +02:00
public class BlockAncientLeaves extends LeavesBlock implements
2019-11-04 19:08:49 +01:00
IModItem, IModelProvider, IColorProvidingBlock, IColorProvidingItem {
2018-10-13 23:46:30 +02:00
public BlockAncientLeaves() {
2019-11-04 19:08:49 +01:00
super(ModBlocks.prop(Material.LEAVES, MaterialColor.PINK));
2018-11-29 17:58:47 +01:00
ModRegistry.add(this);
2020-01-23 19:20:47 +01:00
ModRegistry.add(new ModTileType<>(TileEntityAncientLeaves::new, this));
2018-10-13 23:46:30 +02:00
}
@Override
public String getBaseName() {
return "ancient_leaves";
}
@Nullable
@Override
2019-11-04 19:08:49 +01:00
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
2020-01-23 19:20:47 +01:00
return new TileEntityAncientLeaves();
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() {
2019-01-30 17:51:39 +01:00
return (state, worldIn, 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)
2019-11-04 19:08:49 +01:00
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
super.animateTick(stateIn, worldIn, pos, rand);
if (rand.nextFloat() >= 0.95F && !worldIn.getBlockState(pos.down()).isOpaqueCube(worldIn, pos)) {
2018-10-14 16:12:33 +02:00
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileEntityAncientLeaves) {
2018-10-20 21:19:08 +02:00
if (((TileEntityAncientLeaves) tile).getAuraContainer(null).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,
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
2019-11-04 19:08:49 +01:00
public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
super.tick(state, worldIn, pos, random);
2018-10-14 16:12:33 +02:00
if (!worldIn.isRemote) {
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileEntityAncientLeaves) {
2018-10-20 21:19:08 +02:00
if (((TileEntityAncientLeaves) tile).getAuraContainer(null).getStoredAura() <= 0) {
2018-10-14 16:12:33 +02:00
worldIn.setBlockState(pos, ModBlocks.DECAYED_LEAVES.getDefaultState());
}
}
}
}
2018-10-13 23:46:30 +02:00
}