Search in sources :

Example 1 with IShearable

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

the class HardcoreWoolHandler method shearSheep.

private void shearSheep(PlayerInteractEvent event, Entity target) {
    if (!InteractionBWM.HARDCORE_SHEARING)
        return;
    World world = event.getWorld();
    EntityPlayer player = event.getEntityPlayer();
    BlockPos pos = player.getPosition();
    ItemStack tool = event.getItemStack();
    if (!world.isRemote && target instanceof IShearable && isShears(tool)) {
        event.setCanceled(true);
        event.setCancellationResult(EnumActionResult.PASS);
        IShearable sheep = (IShearable) target;
        if (!sheep.isShearable(tool, world, pos))
            return;
        java.util.Random rand = new java.util.Random();
        for (ItemStack stack : InteractionBWM.convertShearedWool(sheep.onSheared(tool, world, pos, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, tool)))) {
            EntityItem ent = target.entityDropItem(stack, 1.0F);
            ent.motionY += rand.nextFloat() * 0.05F;
            ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
            ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
        }
        tool.damageItem(1, player);
        event.setCancellationResult(EnumActionResult.SUCCESS);
    }
}
Also used : IShearable(net.minecraftforge.common.IShearable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with IShearable

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

the class HardcoreWoolHandler method sheepDropEvent.

@SubscribeEvent
public void sheepDropEvent(LivingDropsEvent event) {
    Entity entity = event.getEntity();
    World world = entity.world;
    if (entity instanceof IShearable && !world.isRemote) {
        InteractionBWM.convertShearedWoolEntities(event.getDrops());
    }
}
Also used : Entity(net.minecraft.entity.Entity) IShearable(net.minecraftforge.common.IShearable) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IShearable

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

the class ItemPickaxeConvenient 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 4 with IShearable

use of net.minecraftforge.common.IShearable in project EnderIO by SleepyTrousers.

the class ItemDarkSteelShears method itemInteractionForEntity.

@Override
public boolean itemInteractionForEntity(@Nonnull ItemStack itemstack, @Nonnull EntityPlayer player, @Nonnull EntityLivingBase entity, @Nonnull EnumHand hand) {
    if (entity.world.isRemote) {
        return false;
    }
    int powerStored = getStoredPower(player);
    if (powerStored < Config.darkSteelShearsPowerUsePerDamagePoint) {
        return super.itemInteractionForEntity(itemstack, player, entity, hand);
    }
    if (entity instanceof IShearable) {
        AxisAlignedBB bb = new AxisAlignedBB(entity.posX - Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posY - Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posZ - Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posX + Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posY + Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posZ + Config.darkSteelShearsEntityAreaBoostWhenPowered);
        List<Entity> sortedTargets = new ArrayList<Entity>(entity.world.getEntitiesWithinAABB(Entity.class, bb, selectShearable));
        entityComparator.refPoint = entity;
        Collections.sort(sortedTargets, entityComparator);
        boolean result = false;
        int maxSheep = Math.min(sortedTargets.size(), powerStored / Config.darkSteelShearsPowerUsePerDamagePoint);
        for (int i = 0; i < maxSheep; i++) {
            Entity entity2 = sortedTargets.get(i);
            if (entity2 instanceof EntityLivingBase && super.itemInteractionForEntity(itemstack, player, (EntityLivingBase) entity2, hand)) {
                result = true;
            }
        }
        return result;
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) IShearable(net.minecraftforge.common.IShearable) ArrayList(java.util.ArrayList) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 5 with IShearable

use of net.minecraftforge.common.IShearable in project EnderIO by SleepyTrousers.

the class TreeFarmer method harvestSingleBlock.

void harvestSingleBlock(@Nonnull IFarmer farm, @Nonnull final World world, @Nonnull final HarvestResult result, @Nonnull final BlockPos harvestPos) {
    float chance = 1.0F;
    NNList<ItemStack> drops = new NNList<>();
    final IBlockState state = farm.getBlockState(harvestPos);
    final Block blk = state.getBlock();
    if (blk instanceof IShearable && hasShears && ((shearCount / result.getHarvestedBlocks().size() + noShearingPercentage) < 100)) {
        drops.addAll(((IShearable) blk).onSheared(farm.getTool(FarmingTool.SHEARS), world, harvestPos, 0));
        shearCount += 100;
        farm.registerAction(FarmingAction.HARVEST, FarmingTool.SHEARS, state, harvestPos);
        hasShears = farm.hasTool(FarmingTool.SHEARS);
        if (!hasShears) {
            farm.setNotification(FarmNotification.NO_SHEARS);
        }
    } else {
        FarmingTool tool = isWood(blk) || !hasHoe ? FarmingTool.AXE : FarmingTool.HOE;
        blk.getDrops(drops, world, harvestPos, state, fortune);
        EntityPlayerMP joe = farm.startUsingItem(tool);
        chance = ForgeEventFactory.fireBlockHarvesting(drops, joe.world, harvestPos, state, fortune, chance, false, joe);
        farm.registerAction(FarmingAction.HARVEST, tool, state, harvestPos);
        NNList.wrap(farm.endUsingItem(tool)).apply(new Callback<ItemStack>() {

            @Override
            public void apply(@Nonnull ItemStack drop) {
                result.getDrops().add(new EntityItem(world, harvestPos.getX() + 0.5, harvestPos.getY() + 0.5, harvestPos.getZ() + 0.5, drop.copy()));
            }
        });
        if (tool == FarmingTool.AXE) {
            hasAxe = farm.hasTool(FarmingTool.AXE);
            if (!hasAxe) {
                farm.setNotification(FarmNotification.NO_AXE);
            }
        } else {
            hasHoe = farm.hasTool(FarmingTool.HOE);
            if (!hasHoe) {
                farm.setNotification(FarmNotification.NO_HOE);
            }
        }
    }
    BlockPos farmPos = farm.getLocation();
    for (ItemStack drop : drops) {
        if (world.rand.nextFloat() <= chance) {
            result.getDrops().add(new EntityItem(world, farmPos.getX() + 0.5, farmPos.getY() + 0.5, farmPos.getZ() + 0.5, drop.copy()));
        }
    }
    farm.getWorld().setBlockToAir(harvestPos);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FarmingTool(crazypants.enderio.base.farming.FarmingTool) NNList(com.enderio.core.common.util.NNList) IShearable(net.minecraftforge.common.IShearable) Block(net.minecraft.block.Block) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

IShearable (net.minecraftforge.common.IShearable)16 Block (net.minecraft.block.Block)11 ItemStack (net.minecraft.item.ItemStack)10 IBlockState (net.minecraft.block.state.IBlockState)7 BlockPos (net.minecraft.util.math.BlockPos)5 Entity (net.minecraft.entity.Entity)4 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 World (net.minecraft.world.World)3 BlockLeaves (net.minecraft.block.BlockLeaves)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