Search in sources :

Example 11 with IShearable

use of net.minecraftforge.common.IShearable in project BetterWithAddons by DaedalusGame.

the class ItemAxeConvenient method onBlockStartBreak.

@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
    if (player.world.isRemote || player.capabilities.isCreativeMode) {
        return false;
    }
    IBlockState state = player.world.getBlockState(pos);
    Block block = state.getBlock();
    if (canShear(itemstack, state) && block instanceof IShearable) {
        IShearable target = (IShearable) block;
        if (target.isShearable(itemstack, player.world, pos)) {
            List<ItemStack> drops = target.onSheared(itemstack, player.world, pos, getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack));
            for (ItemStack stack : drops) {
                InventoryUtil.addItemToPlayer(player, stack);
            }
            itemstack.damageItem(1, player);
            player.addStat(getBlockStats(block));
            // TODO: Move to IShearable implementors in 1.12+
            player.world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IShearable(net.minecraftforge.common.IShearable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 12 with IShearable

use of net.minecraftforge.common.IShearable in project BetterWithAddons by DaedalusGame.

the class ItemSpadeConvenient method onBlockStartBreak.

@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
    if (player.world.isRemote || player.capabilities.isCreativeMode) {
        return false;
    }
    IBlockState state = player.world.getBlockState(pos);
    Block block = state.getBlock();
    if (canShear(itemstack, state) && block instanceof IShearable) {
        IShearable target = (IShearable) block;
        if (target.isShearable(itemstack, player.world, pos)) {
            List<ItemStack> drops = target.onSheared(itemstack, player.world, pos, getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack));
            for (ItemStack stack : drops) {
                InventoryUtil.addItemToPlayer(player, stack);
            }
            itemstack.damageItem(1, player);
            player.addStat(getBlockStats(block));
            // TODO: Move to IShearable implementors in 1.12+
            player.world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IShearable(net.minecraftforge.common.IShearable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 13 with IShearable

use of net.minecraftforge.common.IShearable in project BetterWithAddons by DaedalusGame.

the class ItemSwordConvenient method onBlockStartBreak.

@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
    if (player.world.isRemote || player.capabilities.isCreativeMode) {
        return false;
    }
    IBlockState state = player.world.getBlockState(pos);
    Block block = state.getBlock();
    if (canShear(itemstack, state) && block instanceof IShearable) {
        IShearable target = (IShearable) block;
        if (target.isShearable(itemstack, player.world, pos)) {
            List<ItemStack> drops = target.onSheared(itemstack, player.world, pos, getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack));
            for (ItemStack stack : drops) {
                InventoryUtil.addItemToPlayer(player, stack);
            }
            itemstack.damageItem(1, player);
            player.addStat(getBlockStats(block));
            // TODO: Move to IShearable implementors in 1.12+
            player.world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IShearable(net.minecraftforge.common.IShearable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 14 with IShearable

use of net.minecraftforge.common.IShearable in project pnc-repressurized by TeamPneumatic.

the class EntityVortex method onImpact.

@Override
protected void onImpact(RayTraceResult objectPosition) {
    if (objectPosition.entityHit != null) {
        Entity entity = objectPosition.entityHit;
        entity.motionX += motionX;
        entity.motionY += motionY;
        entity.motionZ += motionZ;
        if (!entity.world.isRemote && entity instanceof IShearable) {
            IShearable shearable = (IShearable) entity;
            BlockPos pos = new BlockPos(posX, posY, posZ);
            if (shearable.isShearable(ItemStack.EMPTY, world, pos)) {
                List<ItemStack> drops = shearable.onSheared(ItemStack.EMPTY, world, pos, 0);
                for (ItemStack stack : drops) {
                    PneumaticCraftUtils.dropItemOnGround(stack, world, entity.posX, entity.posY, entity.posZ);
                }
            }
        }
    } else {
        Block block = world.getBlockState(objectPosition.getBlockPos()).getBlock();
        if (block instanceof IPlantable || block instanceof BlockLeaves) {
            motionX = oldMotionX;
            motionY = oldMotionY;
            motionZ = oldMotionZ;
        } else {
            setDead();
        }
    }
    hitCounter++;
    if (hitCounter > 20)
        setDead();
}
Also used : Entity(net.minecraft.entity.Entity) BlockLeaves(net.minecraft.block.BlockLeaves) IShearable(net.minecraftforge.common.IShearable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 15 with IShearable

use of net.minecraftforge.common.IShearable in project BiomesOPlenty by Glitchfiend.

the class ItemFlowerBasket method isStackSuitableForBasket.

public static boolean isStackSuitableForBasket(@Nonnull ItemStack stack) {
    Item item = stack.getItem();
    Block block = Block.getBlockFromItem(item);
    return !(item instanceof ItemFlowerBasket) && (block instanceof IPlantable || block instanceof IGrowable || block instanceof IShearable || block instanceof BlockBOPMushroom || item instanceof ItemSeedFood || item instanceof ItemSeeds || item == Items.REEDS || item == Items.APPLE || item == Items.MELON || item == Items.BEETROOT || item == Items.WHEAT || item == Items.CHORUS_FRUIT || item == BOPItems.berries || item == BOPItems.pear || item == BOPItems.peach || item == BOPItems.persimmon || item == BOPItems.pinecone || item == BOPItems.turnip);
}
Also used : IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) IShearable(net.minecraftforge.common.IShearable) Block(net.minecraft.block.Block) BlockBOPMushroom(biomesoplenty.common.block.BlockBOPMushroom)

Aggregations

IShearable (net.minecraftforge.common.IShearable)16 Block (net.minecraft.block.Block)12 ItemStack (net.minecraft.item.ItemStack)11 IBlockState (net.minecraft.block.state.IBlockState)7 BlockPos (net.minecraft.util.math.BlockPos)5 EntityItem (net.minecraft.entity.item.EntityItem)4 IPlantable (net.minecraftforge.common.IPlantable)4 NNList (com.enderio.core.common.util.NNList)3 ArrayList (java.util.ArrayList)3 Entity (net.minecraft.entity.Entity)3 BlockLeaves (net.minecraft.block.BlockLeaves)2 World (net.minecraft.world.World)2 BlockBOPMushroom (biomesoplenty.common.block.BlockBOPMushroom)1 Vector3d (com.flowpowered.math.vector.Vector3d)1 IHarvestResult (crazypants.enderio.api.farm.IHarvestResult)1 FarmingTool (crazypants.enderio.base.farming.FarmingTool)1 Random (java.util.Random)1 UUID (java.util.UUID)1 IGrowable (net.minecraft.block.IGrowable)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1