2018-10-13 23:46:30 +02:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
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.*;
|
|
|
|
import net.minecraft.block.BlockLeaves;
|
|
|
|
import net.minecraft.block.BlockPlanks;
|
|
|
|
import net.minecraft.block.ITileEntityProvider;
|
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.client.renderer.color.IBlockColor;
|
|
|
|
import net.minecraft.client.renderer.color.IItemColor;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class BlockAncientLeaves extends BlockLeaves implements
|
|
|
|
IModItem, IModelProvider, IColorProvidingBlock, IColorProvidingItem, ITileEntityProvider {
|
|
|
|
|
|
|
|
public BlockAncientLeaves() {
|
|
|
|
this.leavesFancy = true;
|
|
|
|
ModRegistry.addItemOrBlock(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return "ancient_leaves";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldAddCreative() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreInit(FMLPreInitializationEvent event) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInit(FMLInitializationEvent event) {
|
|
|
|
GameRegistry.registerTileEntity(TileEntityAncientLeaves.class, new ResourceLocation(NaturesAura.MOD_ID, "ancient_leaves"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostInit(FMLPostInitializationEvent event) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
|
|
|
|
return Collections.singletonList(new ItemStack(this, 1, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected BlockStateContainer createBlockState() {
|
|
|
|
return new BlockStateContainer(this, CHECK_DECAY, DECAYABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
|
|
boolean check = (meta & 1) != 0;
|
|
|
|
boolean decay = (meta & 2) != 0;
|
|
|
|
|
|
|
|
return this.getDefaultState().withProperty(CHECK_DECAY, check).withProperty(DECAYABLE, decay);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state) {
|
|
|
|
boolean check = state.getValue(CHECK_DECAY);
|
|
|
|
boolean decay = state.getValue(DECAYABLE);
|
|
|
|
|
|
|
|
return (check ? 1 : 0) | (decay ? 1 : 0) << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beginLeavesDecay(IBlockState state, World world, BlockPos pos) {
|
|
|
|
if (!state.getValue(CHECK_DECAY) && state.getValue(DECAYABLE)) {
|
|
|
|
world.setBlockState(pos, state.withProperty(CHECK_DECAY, true), 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
|
|
|
|
super.breakBlock(worldIn, pos, state);
|
|
|
|
worldIn.removeTileEntity(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockPlanks.EnumType getWoodType(int meta) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
2018-10-14 14:27:18 +02:00
|
|
|
return (meta & 2) != 0 ? new TileEntityAncientLeaves() : null;
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public IBlockColor getBlockColor() {
|
|
|
|
return (state, worldIn, pos, tintIndex) -> 0xE480D9;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public IItemColor getItemColor() {
|
|
|
|
return (stack, tintIndex) -> 0xE480D9;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
|
|
|
super.randomDisplayTick(stateIn, worldIn, pos, rand);
|
2018-10-16 17:48:36 +02:00
|
|
|
if (rand.nextFloat() >= 0.95F && !worldIn.getBlockState(pos.down()).isFullBlock()) {
|
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(),
|
|
|
|
0F, 0F, 0F, 0xc46df9,
|
|
|
|
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
|
|
|
|
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
|
|
|
|
return Item.getItemFromBlock(ModBlocks.ANCIENT_SAPLING);
|
|
|
|
}
|
2018-10-14 16:12:33 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
|
|
|
|
super.updateTick(worldIn, pos, state, rand);
|
|
|
|
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
|
|
|
}
|