/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Jul 8, 2015, 4:29:01 PM (GMT)]
*/
package vazkii.botania.common.block;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
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.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import vazkii.botania.api.lexicon.ILexiconable;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.common.block.tile.TileCocoon;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockNames;
public class BlockCocoon extends BlockMod implements ILexiconable {
private static final AxisAlignedBB AABB = new AxisAlignedBB(3.0/16, 0, 3.0/16, 13.0/16, 0.875, 13.0/16);;
protected BlockCocoon() {
super(Material.CLOTH, LibBlockNames.COCOON);
setHardness(3.0F);
setResistance(50.0F);
setSoundType(SoundType.CLOTH);
}
@Nonnull
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) {
return AABB;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Nonnull
@Override
public EnumBlockRenderType getRenderType(IBlockState state) {
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing s, float xs, float ys, float zs) {
TileCocoon cocoon = (TileCocoon) world.getTileEntity(pos);
ItemStack stack = player.getHeldItem(hand);
Item item = stack.getItem();
if(cocoon != null && (item == Items.EMERALD || item == Items.CHORUS_FRUIT)) {
if(!world.isRemote) {
if(item == Items.EMERALD && cocoon.emeraldsGiven < TileCocoon.MAX_EMERALDS) {
if(!player.capabilities.isCreativeMode)
stack.shrink(1);
cocoon.emeraldsGiven++;
world.playEvent(2005, pos, 6 + world.rand.nextInt(4));
} else if(item == Items.CHORUS_FRUIT && cocoon.chorusFruitGiven < TileCocoon.MAX_CHORUS_FRUITS) {
if(!player.capabilities.isCreativeMode)
stack.shrink(1);
cocoon.chorusFruitGiven++;
((WorldServer) world).spawnParticle(EnumParticleTypes.PORTAL, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 32, 0, 0, 0, 0.5);
}
}
return true;
}
return false;
}
@Nonnull
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, @Nonnull IBlockState state, int fortune) {
return new ArrayList<>();
}
@Override
public boolean canSilkHarvest(World world, BlockPos pos, @Nonnull IBlockState state, EntityPlayer player) {
return false;
}
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}
@Nonnull
@Override
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
return new TileCocoon();
}
@Override
public LexiconEntry getEntry(World world, BlockPos pos, EntityPlayer player, ItemStack lexicon) {
return LexiconData.cocoon;
}
}