Search in sources :

Example 1 with ShearsItem

use of net.minecraft.item.ShearsItem in project upgrade-aquatic by team-abnormals.

the class TallBeachgrassBlock method onBlockHarvested.

public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
    DoubleBlockHalf doubleblockhalf = state.get(HALF);
    BlockPos blockpos = doubleblockhalf == DoubleBlockHalf.LOWER ? pos.up() : pos.down();
    BlockState blockstate = worldIn.getBlockState(blockpos);
    if (blockstate.getBlock() == this && blockstate.get(HALF) != doubleblockhalf) {
        worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 35);
        worldIn.playEvent(player, 2001, blockpos, Block.getStateId(blockstate));
        if (!worldIn.isRemote && !player.isCreative() && player.getHeldItemMainhand().getItem() instanceof ShearsItem) {
            spawnAsEntity(worldIn, pos, new ItemStack(UABlocks.BEACHGRASS.get()));
            spawnAsEntity(worldIn, pos.up(), new ItemStack(UABlocks.BEACHGRASS.get()));
        } else if (!worldIn.isRemote && !player.isCreative() && !(player.getHeldItemMainhand().getItem() instanceof ShearsItem)) {
            Random rand = new Random();
            if (rand.nextFloat() < 0.125F) {
                spawnAsEntity(worldIn, pos, new ItemStack(Items.BEETROOT_SEEDS));
            }
        }
    }
    super.onBlockHarvested(worldIn, pos, state, player);
}
Also used : BlockState(net.minecraft.block.BlockState) Random(java.util.Random) DoubleBlockHalf(net.minecraft.state.properties.DoubleBlockHalf) BlockPos(net.minecraft.util.math.BlockPos) ShearsItem(net.minecraft.item.ShearsItem) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ShearsItem

use of net.minecraft.item.ShearsItem in project meteor-client by MeteorDevelopment.

the class AutoShearer method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    entity = null;
    for (Entity entity : mc.world.getEntities()) {
        if (!(entity instanceof SheepEntity) || ((SheepEntity) entity).isSheared() || ((SheepEntity) entity).isBaby() || mc.player.distanceTo(entity) > distance.get())
            continue;
        boolean findNewShears = false;
        if (mc.player.getInventory().getMainHandStack().getItem() instanceof ShearsItem) {
            if (antiBreak.get() && mc.player.getInventory().getMainHandStack().getDamage() >= mc.player.getInventory().getMainHandStack().getMaxDamage() - 1)
                findNewShears = true;
        } else if (mc.player.getInventory().offHand.get(0).getItem() instanceof ShearsItem) {
            if (antiBreak.get() && mc.player.getInventory().offHand.get(0).getDamage() >= mc.player.getInventory().offHand.get(0).getMaxDamage() - 1)
                findNewShears = true;
            else
                offHand = true;
        } else {
            findNewShears = true;
        }
        boolean foundShears = !findNewShears;
        if (findNewShears) {
            FindItemResult shears = InvUtils.findInHotbar(itemStack -> (!antiBreak.get() || (antiBreak.get() && itemStack.getDamage() < itemStack.getMaxDamage() - 1)) && itemStack.getItem() == Items.SHEARS);
            if (InvUtils.swap(shears.slot(), true))
                foundShears = true;
        }
        if (foundShears) {
            this.entity = entity;
            if (rotate.get())
                Rotations.rotate(Rotations.getYaw(entity), Rotations.getPitch(entity), -100, this::interact);
            else
                interact();
            return;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) SheepEntity(net.minecraft.entity.passive.SheepEntity) SheepEntity(net.minecraft.entity.passive.SheepEntity) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) ShearsItem(net.minecraft.item.ShearsItem) EventHandler(meteordevelopment.orbit.EventHandler)

Example 3 with ShearsItem

use of net.minecraft.item.ShearsItem in project minecolonies by Minecolonies.

the class EntityAIWorkAlchemist method harvestMistleToe.

/**
 * Go to a random position with leaves and hit the leaves until getting a mistletoe.
 * @return next state to go to.
 */
private IAIState harvestMistleToe() {
    if (checkForToolOrWeapon(ToolType.SHEARS)) {
        return IDLE;
    }
    if (walkTo == null) {
        final List<BlockPos> leaveList = building.getAllLeavePositions();
        if (leaveList.isEmpty()) {
            return IDLE;
        }
        final BlockPos randomLeaf = leaveList.get(worker.getRandom().nextInt(leaveList.size()));
        if (WorldUtil.isBlockLoaded(world, randomLeaf)) {
            if (world.getBlockState(randomLeaf).getBlock() instanceof LeavesBlock) {
                walkTo = randomLeaf;
            } else {
                building.removeLeafPosition(randomLeaf);
            }
        }
        return HARVEST_MISTLETOE;
    }
    if (WorldUtil.isBlockLoaded(world, walkTo) && world.getBlockState(walkTo).getBlock() instanceof LeavesBlock) {
        if (walkToBlock(walkTo)) {
            return HARVEST_MISTLETOE;
        }
        final BlockState state = world.getBlockState(walkTo);
        final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), stack -> stack.getItem() instanceof ShearsItem);
        worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, slot);
        worker.swing(Hand.MAIN_HAND);
        world.playSound(null, walkTo, state.getSoundType(world, walkTo, worker).getBreakSound(), SoundCategory.BLOCKS, state.getSoundType(world, walkTo, worker).getVolume(), state.getSoundType(world, walkTo, worker).getPitch());
        Network.getNetwork().sendToTrackingEntity(new BlockParticleEffectMessage(walkTo, state, worker.getRandom().nextInt(7) - 1), worker);
        if (worker.getRandom().nextInt(120) < 1) {
            worker.decreaseSaturationForContinuousAction();
            InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(ModItems.mistletoe, 1));
            walkTo = null;
            worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
            return INVENTORY_FULL;
        }
    } else {
        walkTo = null;
        return IDLE;
    }
    return HARVEST_MISTLETOE;
}
Also used : BlockParticleEffectMessage(com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage) BlockPos(net.minecraft.util.math.BlockPos) ShearsItem(net.minecraft.item.ShearsItem) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ShearsItem

use of net.minecraft.item.ShearsItem in project Client by MatHax.

the class AutoShearer method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    entity = null;
    for (Entity entity : mc.world.getEntities()) {
        if (!(entity instanceof SheepEntity) || ((SheepEntity) entity).isSheared() || ((SheepEntity) entity).isBaby() || mc.player.distanceTo(entity) > distance.get())
            continue;
        boolean findNewShears = false;
        if (mc.player.getInventory().getMainHandStack().getItem() instanceof ShearsItem) {
            if (antiBreak.get() && mc.player.getInventory().getMainHandStack().getDamage() >= mc.player.getInventory().getMainHandStack().getMaxDamage() - 1)
                findNewShears = true;
        } else if (mc.player.getInventory().offHand.get(0).getItem() instanceof ShearsItem) {
            if (antiBreak.get() && mc.player.getInventory().offHand.get(0).getDamage() >= mc.player.getInventory().offHand.get(0).getMaxDamage() - 1)
                findNewShears = true;
            else
                offHand = true;
        } else {
            findNewShears = true;
        }
        boolean foundShears = !findNewShears;
        if (findNewShears) {
            FindItemResult shears = InvUtils.findInHotbar(itemStack -> (!antiBreak.get() || (antiBreak.get() && itemStack.getDamage() < itemStack.getMaxDamage() - 1)) && itemStack.getItem() == Items.SHEARS);
            if (InvUtils.swap(shears.slot(), true))
                foundShears = true;
        }
        if (foundShears) {
            this.entity = entity;
            if (rotate.get())
                Rotations.rotate(Rotations.getYaw(entity), Rotations.getPitch(entity), -100, this::interact);
            else
                interact();
            return;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) SheepEntity(net.minecraft.entity.passive.SheepEntity) SheepEntity(net.minecraft.entity.passive.SheepEntity) FindItemResult(mathax.client.utils.player.FindItemResult) ShearsItem(net.minecraft.item.ShearsItem) EventHandler(mathax.client.eventbus.EventHandler)

Example 5 with ShearsItem

use of net.minecraft.item.ShearsItem in project AurorasDecorations by LambdAurora.

the class FloweringAzaleaLogBlock method onUse.

/* Interaction */
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    ItemStack heldStack = player.getStackInHand(hand);
    if (heldStack.isEmpty()) {
        return ActionResult.FAIL;
    }
    Item held = heldStack.getItem();
    if (!(held instanceof ShearsItem)) {
        return ActionResult.FAIL;
    }
    if (this.normalSupplier != null) {
        world.playSound(player, pos, AurorasDecoSounds.FLOWERING_SHEAR_SOUND_EVENT, SoundCategory.BLOCKS, 1.f, 1.f);
        if (player instanceof ServerPlayerEntity) {
            Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity) player, pos, heldStack);
        }
        world.setBlockState(pos, this.normalSupplier.get().getDefaultState().with(PillarBlock.AXIS, state.get(PillarBlock.AXIS)), 11);
        heldStack.damage(1, player, p -> p.sendToolBreakStatus(hand));
        return ActionResult.SUCCESS;
    }
    return super.onUse(state, world, pos, player, hand, hit);
}
Also used : ShearsItem(net.minecraft.item.ShearsItem) Item(net.minecraft.item.Item) ShearsItem(net.minecraft.item.ShearsItem) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ShearsItem (net.minecraft.item.ShearsItem)6 ItemStack (net.minecraft.item.ItemStack)4 BlockPos (net.minecraft.util.math.BlockPos)3 BlockState (net.minecraft.block.BlockState)2 Entity (net.minecraft.entity.Entity)2 Item (net.minecraft.item.Item)2 CarpetExtraSettings (carpetextra.CarpetExtraSettings)1 BlazePowderDispenserBehavior (carpetextra.dispenser.behaviors.BlazePowderDispenserBehavior)1 CarvePumpkinDispenserBehavior (carpetextra.dispenser.behaviors.CarvePumpkinDispenserBehavior)1 CauldronEmptyingDispenserBehavior (carpetextra.dispenser.behaviors.CauldronEmptyingDispenserBehavior)1 CauldronFillingDispenserBehavior (carpetextra.dispenser.behaviors.CauldronFillingDispenserBehavior)1 CauldronWaterDispenserBehavior (carpetextra.dispenser.behaviors.CauldronWaterDispenserBehavior)1 DragonBreathDispenserBehavior (carpetextra.dispenser.behaviors.DragonBreathDispenserBehavior)1 FeedAnimalDispenserBehavior (carpetextra.dispenser.behaviors.FeedAnimalDispenserBehavior)1 FeedMooshroomDispenserBehavior (carpetextra.dispenser.behaviors.FeedMooshroomDispenserBehavior)1 FillMinecartDispenserBehavior (carpetextra.dispenser.behaviors.FillMinecartDispenserBehavior)1 FireChargeDispenserBehavior (carpetextra.dispenser.behaviors.FireChargeDispenserBehavior)1 FlowerPotDispenserBehavior (carpetextra.dispenser.behaviors.FlowerPotDispenserBehavior)1 MilkAnimalDispenserBehavior (carpetextra.dispenser.behaviors.MilkAnimalDispenserBehavior)1 MilkMooshroomDispenserBehavior (carpetextra.dispenser.behaviors.MilkMooshroomDispenserBehavior)1