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);
}
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;
}
}
}
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;
}
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;
}
}
}
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);
}
Aggregations