/******************************************************************************* * AbyssalCraft * Copyright (c) 2012 - 2017 Shinoow. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-3.0.txt * * Contributors: * Shinoow - implementation ******************************************************************************/ package com.shinoow.abyssalcraft.common.blocks; import java.util.List; import java.util.Random; import net.minecraft.block.BlockContainer; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import com.shinoow.abyssalcraft.common.blocks.BlockTieredEnergyPedestal.EnumDimType; import com.shinoow.abyssalcraft.common.blocks.tile.TileEntityTieredSacrificialAltar; import com.shinoow.abyssalcraft.lib.ACConfig; import com.shinoow.abyssalcraft.lib.ACTabs; import com.shinoow.abyssalcraft.lib.util.blocks.SingletonInventoryUtil; public class BlockTieredSacrificialAltar extends BlockContainer { public static final PropertyEnum DIMENSION = PropertyEnum.create("dimension", EnumDimType.class); public BlockTieredSacrificialAltar(){ super(Material.ROCK); setHardness(6.0F); setResistance(12.0F); setUnlocalizedName("tieredsacrificialaltar"); setSoundType(SoundType.STONE); setCreativeTab(ACTabs.tabDecoration); setHarvestLevel("pickaxe", 0); } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return new AxisAlignedBB(0.15F, 0.0F, 0.15F, 0.85F, 1.0F, 0.85F); } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, NonNullList<ItemStack> par3List) { par3List.add(new ItemStack(par1, 1, 0)); par3List.add(new ItemStack(par1, 1, 1)); par3List.add(new ItemStack(par1, 1, 2)); par3List.add(new ItemStack(par1, 1, 3)); } @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityTieredSacrificialAltar(); } @Override public boolean isOpaqueCube(IBlockState state){ return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public int damageDropped (IBlockState state) { return ((EnumDimType)state.getValue(DIMENSION)).getMeta(); } @Override public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random) { super.randomDisplayTick(state, world, pos, random); int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); if(ACConfig.particleBlock){ world.spawnParticle(EnumParticleTypes.FLAME, x + 0.75, y + 1.05, z + 0.75, 0.0D, 0.0D, 0.0D); world.spawnParticle(EnumParticleTypes.FLAME, x + 0.25, y + 1.05, z + 0.75, 0.0D, 0.0D, 0.0D); world.spawnParticle(EnumParticleTypes.FLAME, x + 0.25, y + 1.05, z + 0.25, 0.0D, 0.0D, 0.0D); world.spawnParticle(EnumParticleTypes.FLAME, x + 0.75, y + 1.05, z + 0.25, 0.0D, 0.0D, 0.0D); world.spawnParticle(EnumParticleTypes.FLAME, x + 0.75, y + 1.05, z + 0.75, 0.0D, 0.0D, 0.0D); world.spawnParticle(EnumParticleTypes.FLAME, x + 0.25, y + 1.05, z + 0.75, 0.0D, 0.0D, 0.0D); world.spawnParticle(EnumParticleTypes.FLAME, x + 0.25, y + 1.05, z + 0.25, 0.0D, 0.0D, 0.0D); world.spawnParticle(EnumParticleTypes.FLAME, x + 0.75, y + 1.05, z + 0.25, 0.0D, 0.0D, 0.0D); } TileEntity tile = world.getTileEntity(pos); if(tile != null && tile instanceof TileEntityTieredSacrificialAltar){ int timer = ((TileEntityTieredSacrificialAltar) tile).getCooldownTimer(); if(timer > 0) world.spawnParticle(EnumParticleTypes.LAVA, x + 0.5, y + 1, z + 0.5, 0, 0, 0); } } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { return SingletonInventoryUtil.handleBlockActivation(world, pos, player, player.getHeldItem(hand)); } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } @Override public void breakBlock(World world, BlockPos pos, IBlockState state) { Random rand = new Random(); TileEntityTieredSacrificialAltar altar = (TileEntityTieredSacrificialAltar) world.getTileEntity(pos); if(altar != null){ if(!altar.getItem().isEmpty()){ float f = rand.nextFloat() * 0.8F + 0.1F; float f1 = rand.nextFloat() * 0.8F + 0.1F; float f2 = rand.nextFloat() * 0.8F + 0.1F; EntityItem item = new EntityItem(world, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, altar.getItem()); float f3 = 0.05F; item.motionX = (float)rand.nextGaussian() * f3; item.motionY = (float)rand.nextGaussian() * f3 + 0.2F; item.motionZ = (float)rand.nextGaussian() * f3; world.spawnEntity(item); } ItemStack stack = new ItemStack(getItemDropped(state, rand, 1), 1, damageDropped(state)); if(!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound()); NBTTagCompound data = new NBTTagCompound(); altar.writeToNBT(data); stack.getTagCompound().setFloat("PotEnergy", data.getFloat("PotEnergy")); stack.getTagCompound().setInteger("CollectionLimit", data.getInteger("CollectionLimit")); stack.getTagCompound().setInteger("CoolDown", data.getInteger("CoolDown")); float f = rand.nextFloat() * 0.8F + 0.1F; float f1 = rand.nextFloat() * 0.8F + 0.1F; float f2 = rand.nextFloat() * 0.8F + 0.1F; EntityItem item = new EntityItem(world, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, stack); float f3 = 0.05F; item.motionX = (float)rand.nextGaussian() * f3; item.motionY = (float)rand.nextGaussian() * f3 + 0.2F; item.motionZ = (float)rand.nextGaussian() * f3; world.spawnEntity(item); } super.breakBlock(world, pos, state); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { if(stack.hasTagCompound()){ TileEntity tile = worldIn.getTileEntity(pos); if(tile != null && tile instanceof TileEntityTieredSacrificialAltar){ NBTTagCompound data = new NBTTagCompound(); tile.writeToNBT(data); data.setFloat("PotEnergy", stack.getTagCompound().getFloat("PotEnergy")); data.setInteger("CollectionLimit", stack.getTagCompound().getInteger("CollectionLimit")); data.setInteger("CoolDown", stack.getTagCompound().getInteger("CoolDown")); tile.readFromNBT(data); } } } @Override public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { return new java.util.ArrayList<ItemStack>(); } @Override public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(DIMENSION, EnumDimType.byMetadata(meta)); } @Override public int getMetaFromState(IBlockState state) { return ((EnumDimType)state.getValue(DIMENSION)).getMeta(); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer.Builder(this).add(DIMENSION).build(); } }