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;
|
2020-01-21 23:02:39 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
|
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;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
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);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return "ancient_leaves";
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
public void onInit(FMLCommonSetupEvent event) {
|
|
|
|
//GameRegistry.registerTileEntity(TileEntityAncientLeaves.class, new ResourceLocation(NaturesAura.MOD_ID, "ancient_leaves"));
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
/* Appears to be handled already somewhere by super
|
2018-10-13 23:46:30 +02:00
|
|
|
@Override
|
2019-11-04 19:08:49 +01:00
|
|
|
public void beginLeaveDecay(BlockState state, IWorldReader world, BlockPos pos) {
|
|
|
|
if (!state.get(DISTANCE).intValue() && state.getValue(DECAYABLE)) {
|
|
|
|
world.getChunk(pos).setBlockState(pos, state.with(CHECK_DECAY, true), false);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-04 19:08:49 +01:00
|
|
|
*/
|
|
|
|
|
2018-10-13 23:46:30 +02:00
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
/* // Appears to auto remove TE during setting of the state by the world
|
2018-10-13 23:46:30 +02:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void breakBlock(World worldIn, BlockPos pos, BlockState state) {
|
2018-10-13 23:46:30 +02:00
|
|
|
super.breakBlock(worldIn, pos, state);
|
|
|
|
worldIn.removeTileEntity(pos);
|
|
|
|
}
|
2019-11-04 19:08:49 +01:00
|
|
|
*/
|
2018-10-13 23:46:30 +02:00
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2019-11-04 19:08:49 +01:00
|
|
|
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
2020-01-21 23:02:39 +01:00
|
|
|
return ModTileEntities.ANCIENT_LEAVES.create();
|
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,
|
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
|
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
|
|
|
}
|