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.*;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.LeavesBlock;
|
2018-10-13 23:46:30 +02:00
|
|
|
import net.minecraft.block.BlockPlanks;
|
|
|
|
import net.minecraft.block.ITileEntityProvider;
|
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.block.state.BlockStateContainer;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.BlockState;
|
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.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;
|
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.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
public class BlockAncientLeaves extends LeavesBlock implements
|
2018-11-29 17:58:47 +01:00
|
|
|
IModItem, ICreativeItem, IModelProvider, IColorProvidingBlock, IColorProvidingItem, ITileEntityProvider {
|
2018-10-13 23:46:30 +02:00
|
|
|
|
|
|
|
public BlockAncientLeaves() {
|
|
|
|
this.leavesFancy = true;
|
2018-11-29 17:58:47 +01:00
|
|
|
ModRegistry.add(this);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 11:40:36 +01:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public MaterialColor getMapColor(BlockState state, IBlockAccess worldIn, BlockPos pos) {
|
|
|
|
return MaterialColor.PINK;
|
2018-11-28 11:40:36 +01:00
|
|
|
}
|
|
|
|
|
2018-10-13 23:46:30 +02:00
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return "ancient_leaves";
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockState getStateFromMeta(int meta) {
|
2018-10-13 23:46:30 +02:00
|
|
|
boolean check = (meta & 1) != 0;
|
|
|
|
boolean decay = (meta & 2) != 0;
|
|
|
|
|
|
|
|
return this.getDefaultState().withProperty(CHECK_DECAY, check).withProperty(DECAYABLE, decay);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public int getMetaFromState(BlockState state) {
|
2018-10-13 23:46:30 +02:00
|
|
|
boolean check = state.getValue(CHECK_DECAY);
|
|
|
|
boolean decay = state.getValue(DECAYABLE);
|
|
|
|
|
|
|
|
return (check ? 1 : 0) | (decay ? 1 : 0) << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void beginLeavesDecay(BlockState state, World world, BlockPos pos) {
|
2018-10-13 23:46:30 +02:00
|
|
|
if (!state.getValue(CHECK_DECAY) && state.getValue(DECAYABLE)) {
|
|
|
|
world.setBlockState(pos, state.withProperty(CHECK_DECAY, true), 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
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)
|
|
|
|
public void randomDisplayTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
2018-10-13 23:46:30 +02:00
|
|
|
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(),
|
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-10-20 22:30:49 +02:00
|
|
|
public Item getItemDropped(BlockState state, Random rand, int fortune) {
|
2018-10-13 23:46:30 +02:00
|
|
|
return Item.getItemFromBlock(ModBlocks.ANCIENT_SAPLING);
|
|
|
|
}
|
2018-10-14 16:12:33 +02:00
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void updateTick(World worldIn, BlockPos pos, BlockState state, Random rand) {
|
2018-10-14 16:12:33 +02:00
|
|
|
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
|
|
|
}
|