/**
* MrCrayfish's Furniture Mod
* Copyright (C) 2016 MrCrayfish (http://www.mrcrayfish.com/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.mrcrayfish.furniture.blocks;
import java.util.ArrayList;
import java.util.List;
import com.mrcrayfish.furniture.init.FurnitureItems;
import com.mrcrayfish.furniture.tileentity.TileEntityCup;
import com.mrcrayfish.furniture.util.CollisionHelper;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockCup extends Block implements ITileEntityProvider
{
private static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(5 * 0.0625, 0.0, 5 * 0.0625, 11 * 0.0625, 7.5 * 0.0625, 11 * 0.0625);
public BlockCup(Material material)
{
super(material);
this.setSoundType(SoundType.GLASS);
this.setHardness(0.1F);
this.setDefaultState(this.blockState.getBaseState());
}
@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
@Override
public boolean isFullCube(IBlockState state)
{
return false;
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
if (stack.hasTagCompound())
{
NBTTagCompound nbt = stack.getTagCompound();
if (nbt.hasKey("Colour"))
{
int[] rgb = nbt.getIntArray("Colour");
TileEntityCup tileEntityCup = (TileEntityCup) world.getTileEntity(pos);
tileEntityCup.setColour(rgb);
tileEntityCup.setItem(stack);
}
}
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return BOUNDING_BOX;
}
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB axisAligned, List<AxisAlignedBB> axisAlignedList, Entity collidingEntity)
{
super.addCollisionBoxToList(pos, axisAligned, axisAlignedList, BOUNDING_BOX);
}
@Override
public TileEntity createNewTileEntity(World world, int meta)
{
return new TileEntityCup();
}
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
if(worldIn.isRemote)
{
ItemStack drink = getPickBlock(state, null, worldIn, pos, player);
EntityItem entity = new EntityItem(worldIn, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, drink);
worldIn.spawnEntityInWorld(entity);
}
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{
TileEntityCup tileEntityCup = (TileEntityCup) world.getTileEntity(pos);
if (tileEntityCup.getDrink() != null)
{
return tileEntityCup.getDrink().copy();
}
else
{
return new ItemStack(FurnitureItems.itemCup);
}
}
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
List<ItemStack> drops = new ArrayList<ItemStack>();
TileEntityCup tileEntityCup = (TileEntityCup) world.getTileEntity(pos);
if (tileEntityCup.getDrink() != null)
{
drops.add(tileEntityCup.getDrink().copy());
}
else
{
drops.add(new ItemStack(FurnitureItems.itemCup));
}
return drops;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.TRANSLUCENT;
}
}