net.minecraft.util.Hand Java Examples

The following examples show how to use net.minecraft.util.Hand. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CrystalAura.java    From bleachhack-1.14 with GNU General Public License v3.0 8 votes vote down vote up
@Subscribe
public void onTick(EventTick event) {
	delay++;
	int reqDelay = (int) Math.round(20/getSettings().get(3).toSlider().getValue());
	
	for (Entity e: mc.world.getEntities()) {
		if (e instanceof EndCrystalEntity && mc.player.distanceTo(e) < getSettings().get(2).toSlider().getValue()) {
			if (!mc.player.canSee(e) && !getSettings().get(1).toToggle().state) continue;
			if (getSettings().get(0).toToggle().state) EntityUtils.facePos(e.getX(), e.getY() + e.getHeight()/2, e.getZ());
			
			if (delay > reqDelay || reqDelay == 0) {
				mc.player.networkHandler.sendPacket(new PlayerInteractEntityC2SPacket(e, mc.player.isSneaking()));
				mc.player.attack(e);
				mc.player.swingHand(Hand.MAIN_HAND);
				delay=0;
			}
		}
	}
}
 
Example #2
Source File: GuiItem.java    From LibGui with MIT License 6 votes vote down vote up
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
	if (world.isClient) {
		openScreen(); // In its own method to prevent class loading issues
	}
	
	return new TypedActionResult<ItemStack>(ActionResult.SUCCESS, (hand==Hand.MAIN_HAND) ? player.getMainHandStack() : player.getOffHandStack());
}
 
Example #3
Source File: HallowedLogBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
	ItemStack stack = player.getStackInHand(hand);
	if (stack.isEmpty() || !(stack.getItem() instanceof MiningToolItem)) {
		return ActionResult.PASS;
	}
	
	MiningToolItem tool = (MiningToolItem) stack.getItem();
	if (stripped != null && (tool.isEffectiveOn(state) || tool.getMiningSpeed(stack, state) > 1.0F)) {
		world.playSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
		if (!world.isClient) {
			BlockState target = stripped.getDefaultState().with(LogBlock.AXIS, state.get(LogBlock.AXIS));
			world.setBlockState(pos, target);
			stack.damage(1, player, consumedPlayer -> consumedPlayer.sendToolBreakStatus(hand));
		}
		return ActionResult.SUCCESS;
	}
	return ActionResult.PASS;
}
 
Example #4
Source File: Scaffold.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public void placeBlockAuto(BlockPos block) {
	if (lastPlaced.containsKey(block)) return;
	for (Direction d: Direction.values()) {
		if (!WorldUtils.NONSOLID_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
			if (WorldUtils.RIGHTCLICKABLE_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
				mc.player.connection.sendPacket(new CEntityActionPacket(mc.player, Action.START_SNEAKING));}
			mc.player.connection.sendPacket(new CPlayerTryUseItemOnBlockPacket(Hand.MAIN_HAND,
					new BlockRayTraceResult(new Vec3d(block), d.getOpposite(), block.offset(d), false)));
			mc.player.swingArm(Hand.MAIN_HAND);
			mc.world.playSound(block, SoundEvents.BLOCK_NOTE_BLOCK_HAT, SoundCategory.BLOCKS, 1f, 1f, false);
			if (WorldUtils.RIGHTCLICKABLE_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
				mc.player.connection.sendPacket(new CEntityActionPacket(mc.player, Action.STOP_SNEAKING));}
			lastPlaced.put(block, 5);
			return;
		}
	}
}
 
Example #5
Source File: TriggerBotHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate()
{
	ClientPlayerEntity player = MC.player;
	if(player.getAttackCooldownProgress(0) < 1)
		return;
	
	if(MC.crosshairTarget == null
		|| !(MC.crosshairTarget instanceof EntityHitResult))
		return;
	
	Entity target = ((EntityHitResult)MC.crosshairTarget).getEntity();
	if(!isCorrectEntity(target))
		return;
	
	WURST.getHax().autoSwordHack.setSlot();
	
	MC.interactionManager.attackEntity(player, target);
	player.swingHand(Hand.MAIN_HAND);
}
 
Example #6
Source File: CrystalAura.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onTick(EventTick event) {
	delay++;
	int reqDelay = (int) Math.round(20/getSettings().get(3).toSlider().getValue());
	
	for (Entity e: mc.world.getEntities()) {
		if (e instanceof EnderCrystalEntity && mc.player.distanceTo(e) < getSettings().get(2).toSlider().getValue()) {
			if (!mc.player.canSee(e) && !getSettings().get(1).toToggle().state) continue;
			if (getSettings().get(0).toToggle().state) EntityUtils.facePos(e.x, e.y + e.getHeight()/2, e.z);
			
			if (delay > reqDelay || reqDelay == 0) {
				mc.player.networkHandler.sendPacket(new PlayerInteractEntityC2SPacket(e));
				mc.player.attack(e);
				mc.player.swingHand(Hand.MAIN_HAND);
				delay=0;
			}
		}
	}
}
 
Example #7
Source File: CrystalAura.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onTick(EventTick event) {
	delay++;
	int reqDelay = (int) Math.round(20/getSettings().get(3).toSlider().getValue());
	
	for (Entity e: mc.world.getEntities()) {
		if (e instanceof EnderCrystalEntity && mc.player.distanceTo(e) < getSettings().get(2).toSlider().getValue()) {
			if (!mc.player.canSee(e) && !getSettings().get(1).toToggle().state) continue;
			if (getSettings().get(0).toToggle().state) EntityUtils.facePos(e.getX(), e.getY() + e.getHeight()/2, e.getZ());
			
			if (delay > reqDelay || reqDelay == 0) {
				mc.player.networkHandler.sendPacket(new PlayerInteractEntityC2SPacket(e));
				mc.player.attack(e);
				mc.player.swingHand(Hand.MAIN_HAND);
				delay=0;
			}
		}
	}
}
 
Example #8
Source File: BuildRandomHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private boolean tryToPlaceBlock(boolean legitMode, BlockPos pos)
{
	if(!BlockUtils.getState(pos).getMaterial().isReplaceable())
		return false;
	
	if(legitMode)
	{
		if(!placeBlockLegit(pos))
			return false;
		
		IMC.setItemUseCooldown(4);
	}else
	{
		if(!placeBlockSimple_old(pos))
			return false;
		
		MC.player.swingHand(Hand.MAIN_HAND);
		IMC.setItemUseCooldown(4);
	}
	
	lastPos = pos;
	return true;
}
 
Example #9
Source File: ServerPlayerEntity_scarpetEventMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Redirect(method = "consumeItem", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/player/PlayerEntity;consumeItem()V"
))
private void finishedUsingItem(PlayerEntity playerEntity)
{
    if (PLAYER_FINISHED_USING_ITEM.isNeeded())
    {
        Hand hand = getActiveHand();
        ItemStack stack = getActiveItem().copy();
        // do vanilla
        super.consumeItem();
        PLAYER_FINISHED_USING_ITEM.onItemAction((ServerPlayerEntity) (Object)this, hand, stack);
    }
    else
    {
        // do vanilla
        super.consumeItem();
    }
}
 
Example #10
Source File: ChickenEntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean interactMob(PlayerEntity playerEntity_1, Hand hand_1)
{
    ItemStack stack = playerEntity_1.getStackInHand(hand_1);
    if (CarpetExtraSettings.chickenShearing && stack.getItem() == Items.SHEARS && !this.isBaby())
    {
        if (!this.world.isClient)
        {
            this.damage(DamageSource.GENERIC, 1);
            this.dropItem(Items.FEATHER, 1);
            stack.damage(1, (LivingEntity)playerEntity_1, ((playerEntity_1x) -> {
                playerEntity_1x.sendToolBreakStatus(hand_1);
            }));
        }
    }
    return super.interactMob(playerEntity_1, hand_1);
}
 
Example #11
Source File: ItemUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean isPlayerHolding(LivingEntity entity, Predicate<Item> predicate) {
    for (Hand hand : Hand.values()) {
        ItemStack stack = entity.getHeldItem(hand);
        if (!stack.isEmpty()) {
            if (predicate.test(stack.getItem())) {
                return true;
            }
        }
    }
    return false;
}
 
Example #12
Source File: UnlitTorchBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    if (player.getStackInHand(hand).getItem() instanceof FlintAndSteelItem) {
        world.setBlockState(pos, Blocks.TORCH.getDefaultState());
        ItemStack stack = player.getStackInHand(hand).copy();
        stack.damage(1, player, (playerEntity -> {
        }));
        player.setStackInHand(hand, stack);
    }
    return super.onUse(state, world, pos, player, hand, hit);
}
 
Example #13
Source File: OxygenGearItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    if (((GCPlayerAccessor) user).getGearInventory().getStack(5).isEmpty()) {
        ((GCPlayerAccessor) user).getGearInventory().setStack(5, user.getStackInHand(hand));
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    }
    return super.use(world, user, hand);
}
 
Example #14
Source File: ModificationTable.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult result) {
    if (!world.isRemote) {
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof INamedContainerProvider) {
            NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos());
        } else {
            throw new IllegalStateException("Our named container provider is missing!");
        }
        return ActionResultType.SUCCESS;
    }
    return ActionResultType.SUCCESS;
}
 
Example #15
Source File: OxygenMaskItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    if (((GCPlayerAccessor) user).getGearInventory().getStack(4).isEmpty()) {
        ((GCPlayerAccessor) user).getGearInventory().setStack(4, user.getStackInHand(hand));
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    }
    return super.use(world, user, hand);
}
 
Example #16
Source File: ServerPlayNetworkHandler_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerInteractItem", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V"
))
private void onItemClicked(PlayerInteractItemC2SPacket playerInteractItemC2SPacket_1, CallbackInfo ci)
{
    if (PLAYER_USES_ITEM.isNeeded())
    {
        Hand hand = playerInteractItemC2SPacket_1.getHand();
        PLAYER_USES_ITEM.onItemAction(player, hand, player.getStackInHand(hand).copy());
    }
}
 
Example #17
Source File: BlockRotator.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static boolean flipBlockWithCactus(BlockState state, World world, PlayerEntity player, Hand hand, BlockHitResult hit)
{
    if (!player.abilities.allowModifyWorld || !CarpetSettings.flippinCactus || !player_holds_cactus_mainhand(player))
    {
        return false;
    }
    CarpetSettings.impendingFillSkipUpdates = true;
    boolean retval = flip_block(state, world, player, hand, hit);
    CarpetSettings.impendingFillSkipUpdates = false;
    return retval;
}
 
Example #18
Source File: ThermalArmorItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override //should sync with server
public TypedActionResult<ItemStack> use(World world_1, PlayerEntity playerEntity_1, Hand hand_1) {
    SimpleInventoryComponent inv = ((GCPlayerAccessor) playerEntity_1).getGearInventory();
    ItemStack thermalPiece = inv.getStack(getSlotIdForType(getSlotType()));
    if (thermalPiece.isEmpty()) {
        inv.setStack(getSlotIdForType(getSlotType()), playerEntity_1.getStackInHand(hand_1));
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    }
    return super.use(world_1, playerEntity_1, hand_1);
}
 
Example #19
Source File: ServerPlayNetworkHandler_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerInteractBlock", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;interactBlock(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;"
))
private void onBlockInteracted(PlayerInteractBlockC2SPacket playerInteractBlockC2SPacket_1, CallbackInfo ci)
{
    if (PLAYER_RIGHT_CLICKS_BLOCK.isNeeded())
    {
        Hand hand = playerInteractBlockC2SPacket_1.getHand();
        BlockHitResult hitRes = playerInteractBlockC2SPacket_1.getHitY();
        PLAYER_RIGHT_CLICKS_BLOCK.onBlockHit(player, hand, hitRes);
    }
}
 
Example #20
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack)
{
    // this.getStackInHand(this.getActiveHand()), this.activeItemStack)
    handler.call( () ->
    {
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> ListValue.fromItemStack(itemstack)),
                ((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"))
        );
    }, player::getCommandSource);
}
 
Example #21
Source File: ItemEnderPouch.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (player.isShiftKeyDown()) {
        return new ActionResult<>(ActionResultType.PASS, stack);
    }
    if (!world.isRemote) {
        Frequency frequency = Frequency.readFromStack(stack);
        EnderStorageManager.instance(world.isRemote).getStorage(frequency, EnderItemStorage.TYPE).openContainer((ServerPlayerEntity) player, new TranslationTextComponent(stack.getTranslationKey()));
    }
    return new ActionResult<>(ActionResultType.SUCCESS, stack);
}
 
Example #22
Source File: DryingRackBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Deprecated
@Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult blockRayTraceResult)
{
    if (worldIn.isRemote)
        return ActionResultType.SUCCESS;

    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (!(tileEntity instanceof INamedContainerProvider))
        return ActionResultType.FAIL;

    NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity);

    return ActionResultType.SUCCESS;
}
 
Example #23
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack)
{
    // this.getStackInHand(this.getActiveHand()), this.activeItemStack)
    handler.call( () ->
    {
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> ListValue.fromItemStack(itemstack)),
                ((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"))
        );
    }, player::getCommandSource);
}
 
Example #24
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack)
{
    handler.call( () ->
    {
        //ItemStack itemstack = player.getStackInHand(enumhand);
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> ListValue.fromItemStack(itemstack)),
                ((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"))
        );
    }, player::getCommandSource);
}
 
Example #25
Source File: Protocol_1_13.java    From multiconnect with MIT License 5 votes vote down vote up
public static void registerTranslators() {
    ProtocolRegistry.registerOutboundTranslator(BookUpdateC2SPacket.class, buf -> {
        buf.passthroughWrite(ItemStack.class); // book item
        buf.passthroughWrite(Boolean.class); // signed
        buf.skipWrite(Hand.class); // hand
    });
}
 
Example #26
Source File: ClientPlayerInteractionManagerMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void rightClickBlock(BlockPos pos, Direction side, Vec3d hitVec)
{
	interactBlock(client.player, client.world, Hand.MAIN_HAND,
		new BlockHitResult(hitVec, side, pos, false));
	interactItem(client.player, client.world, Hand.MAIN_HAND);
}
 
Example #27
Source File: TileEnderTank.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public boolean activate(PlayerEntity player, int subHit, Hand hand) {
    if (subHit == 4) {
        pressure_state.invert();
        return true;
    }
    return FluidUtil.interactWithFluidHandler(player, hand, getStorage());
}
 
Example #28
Source File: MixinPlayerEntity.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "interact", at = @At("HEAD"), cancellable = true)
private void hookInteractEntity(Entity entity, Hand hand, CallbackInfoReturnable<ActionResult> callback) {
	PlayerEntity player = (PlayerEntity) (Object) this;

	if (player.isSpectator()) {
		return;
	}

	int tries = 1;

	if (player.getEntityWorld().isClient) {
		// TODO: Mimicking a stupid forge bug. They fire this *twice* on the client for some reason.
		// I don't know why. It's hooked in ClientPlayerInteractionManager and in PlayerEntity.
		// ClientPlayerInteractionManager just calls directly into PlayerEntity's version.

		tries = 2;
	}

	for (int i = 0; i < tries; i++) {
		ActionResult result = EntityEvents.onInteractEntity(player, entity, hand);

		if (result != null) {
			callback.setReturnValue(result);
			return;
		}
	}
}
 
Example #29
Source File: KillauraHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPostMotion()
{
	if(target == null)
		return;
	
	ClientPlayerEntity player = MC.player;
	MC.interactionManager.attackEntity(player, target);
	player.swingHand(Hand.MAIN_HAND);
	
	target = null;
}
 
Example #30
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onEntityAction(ServerPlayerEntity player, Entity entity, Hand enumhand)
{
    handler.call( () -> Arrays.asList(
            ((c, t) -> new EntityValue(player)),
            ((c, t) -> new EntityValue(entity))
    ), player::getCommandSource);
}