/** * 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.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.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumWorldBlockLayer; import net.minecraft.util.MovingObjectPosition; 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 { public BlockCup(Material material) { super(material); this.setStepSound(Block.soundTypeGlass); this.setHardness(0.1F); this.setDefaultState(this.blockState.getBaseState()); } @Override public boolean isOpaqueCube() { return false; } @Override public boolean isFullCube() { 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 void setBlockBoundsBasedOnState(IBlockAccess blockAccess, BlockPos pos) { int metadata = getMetaFromState(blockAccess.getBlockState(pos)); float[] data = CollisionHelper.fixRotation(metadata, 5F * 0.0625F, 5F * 0.0625F, 11F * 0.0625F, 11F * 0.0625F); setBlockBounds(data[0], 0.0F, data[1], data[2], 7.5F * 0.0625F, data[3]); } @Override public void addCollisionBoxesToList(World world, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity collidingEntity) { int metadata = getMetaFromState(state); float[] data = CollisionHelper.fixRotation(metadata, 5F * 0.0625F, 5F * 0.0625F, 11F * 0.0625F, 11F * 0.0625F); setBlockBounds(data[0], 0.0F, data[1], data[2], 7.5F * 0.0625F, data[3]); super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity); } @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityCup(); } @Override public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) { ItemStack drink = getPickBlock(null, worldIn, pos); EntityItem entity = new EntityItem(worldIn, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, drink); worldIn.spawnEntityInWorld(entity); } @Override public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos) { 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 EnumWorldBlockLayer getBlockLayer() { return EnumWorldBlockLayer.TRANSLUCENT; } }