类net.minecraft.util.Hand源码实例Demo

下面列出了怎么用net.minecraft.util.Hand的API类实例代码及写法,或者点击链接到github查看源代码。

@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();
    }
}
 
源代码2 项目: the-hallow   文件: HallowedLogBlock.java
@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;
}
 
源代码3 项目: Wurst7   文件: TriggerBotHack.java
@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);
}
 
源代码4 项目: Wurst7   文件: BuildRandomHack.java
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;
}
 
源代码5 项目: carpet-extra   文件: ChickenEntityMixin.java
@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);
}
 
源代码6 项目: bleachhack-1.14   文件: CrystalAura.java
@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;
			}
		}
	}
}
 
源代码7 项目: bleachhack-1.14   文件: Scaffold.java
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;
		}
	}
}
 
源代码8 项目: bleachhack-1.14   文件: CrystalAura.java
@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;
			}
		}
	}
}
 
源代码9 项目: bleachhack-1.14   文件: CrystalAura.java
@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;
			}
		}
	}
}
 
源代码10 项目: Galacticraft-Rewoven   文件: WireBlock.java
@Override
@Deprecated
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    if (!world.isClient() && Galacticraft.configManager.get().isDebugLogEnabled()) {
        Galacticraft.logger.info(((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos));
    }
    return super.onUse(state, world, pos, player, hand, hit);
}
 
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
    if (playerEntity.getStackInHand(hand).getItem() instanceof ShearsItem) {
        world.setBlockState(blockPos, GalacticraftBlocks.CAVERNOUS_VINE.getDefaultState().with(VINES, blockState.get(VINES)));
        world.playSound(blockPos.getX(), blockPos.getY(), blockPos.getZ(), SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 1f, 1f, true);
        return ActionResult.SUCCESS;
    }
    return ActionResult.SUCCESS;
}
 
源代码12 项目: Galacticraft-Rewoven   文件: UnlitWallTorchBlock.java
@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.WALL_TORCH.getDefaultState().with(WallTorchBlock.FACING, state.get(WallTorchBlock.FACING)));
        ItemStack stack = player.getStackInHand(hand).copy();
        stack.damage(1, player, (playerEntity -> {
        }));
        player.setStackInHand(hand, stack);
    }

    return super.onUse(state, world, pos, player, hand, hit);
}
 
源代码13 项目: Galacticraft-Rewoven   文件: UnlitTorchBlock.java
@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);
}
 
源代码14 项目: Galacticraft-Rewoven   文件: MoonBerryBushBlock.java
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
    int age = blockState.get(AGE);
    boolean mature = age == 3;

    if (mature) {
        int amount = 1 + world.random.nextInt(3);
        dropStack(world, blockPos, new ItemStack(GalacticraftItems.MOON_BERRIES, amount));
        world.playSound(null, blockPos, SoundEvents.ITEM_SWEET_BERRIES_PICK_FROM_BUSH, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F);
        world.setBlockState(blockPos, blockState.with(AGE, 1), 2);
        return ActionResult.SUCCESS;
    } else {
        return super.onUse(blockState, world, blockPos, playerEntity, hand, blockHitResult);
    }
}
 
源代码15 项目: Survivalist   文件: TorchFireEventHandling.java
@SubscribeEvent
public void onAttackEntity(AttackEntityEvent ev)
{
    if (!ConfigManager.SERVER.enableTorchFire.get())
        return;

    if (!ev.getTarget().func_230279_az_() && !ev.getTarget().world.isRemote)
    {
        PlayerEntity player = ev.getPlayer();
        ItemStack stack = player.getHeldItem(Hand.MAIN_HAND);
        if (stack.getCount() > 0 && stack.getItem() instanceof BlockItem)
        {
            BlockItem b = (BlockItem) stack.getItem();
            Block bl = b.getBlock();
            if (bl == Blocks.TORCH)
            {
                ev.getTarget().setFire(2);
                if (!ev.getPlayer().isCreative() && rnd.nextFloat() > 0.25)
                {
                    stack.grow(-1);
                    if (stack.getCount() <= 0)
                    {
                        player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
                    }
                }
            }
        }
    }
}
 
源代码16 项目: Galacticraft-Rewoven   文件: ThermalArmorItem.java
@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);
}
 
源代码17 项目: Galacticraft-Rewoven   文件: OxygenGearItem.java
@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);
}
 
源代码18 项目: MiningGadgets   文件: ModificationTable.java
@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;
}
 
源代码19 项目: Galacticraft-Rewoven   文件: OxygenMaskItem.java
@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);
}
 
源代码20 项目: the-hallow   文件: TrumpetItem.java
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
	ItemStack stack = player.getStackInHand(hand);
	
	float soundPitch = (((player.pitch - 90) * 1) / -90);
	
	if (player.isSneaking()) {
		player.playSound(HallowedSounds.MEGALADOOT, 0.8f, 1.0f);
	} else {
		player.playSound(HallowedSounds.DOOT, 0.8f, soundPitch);
	}
	
	return new TypedActionResult<>(ActionResult.SUCCESS, stack);
}
 
源代码21 项目: the-hallow   文件: TinyPumpkinBlockEntity.java
public ActionResult use(PlayerEntity player, Hand hand, BlockHitResult hit) {
	Direction facing = getCachedState().get(HorizontalFacingBlock.FACING);
	Direction hitSide = hit.getSide();
	if (hitSide != facing.rotateYClockwise() && hitSide != facing.rotateYCounterclockwise()) {
		return ActionResult.PASS;
	}
	
	if (!world.isClient) {
		ItemStack handStack = player.getStackInHand(hand);
		boolean isLeft = hitSide == facing.rotateYCounterclockwise();
		ItemStack heldItem = isLeft ? leftItem : rightItem;
		if (!heldItem.isEmpty()) {
			ItemScatterer.spawn(world, pos, DefaultedList.copyOf(ItemStack.EMPTY, heldItem));
			if (isLeft) {
				leftItem = ItemStack.EMPTY;
			} else {
				rightItem = ItemStack.EMPTY;
			}
			sync();
			markDirty();
		} else if (!handStack.isEmpty()) {
			if (isLeft) {
				leftItem = handStack.copy();
				leftItem.setCount(1);
			} else {
				rightItem = handStack.copy();
				rightItem.setCount(1);
			}
			handStack.decrement(1);
			sync();
			markDirty();
		}
	}
	
	return ActionResult.SUCCESS;
}
 
源代码22 项目: the-hallow   文件: PumpkinPieBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
	if (!world.isClient) {
		return this.tryEat(world, pos, state, player);
	}
	ItemStack stack = player.getStackInHand(hand);
	if(stack.isEmpty()) {
		return ActionResult.PASS;
	}
	return this.tryEat(world, pos, state, player);
}
 
源代码23 项目: the-hallow   文件: InfusionPillarBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	InfusionPillarBlockEntity pillarEntity = (InfusionPillarBlockEntity) world.getBlockEntity(blockPos);
	if (pillarEntity != null) {
		if (playerEntity.getStackInHand(hand).isEmpty()) {
			playerEntity.inventory.insertStack(pillarEntity.takeStack());
		} else {
			playerEntity.setStackInHand(hand, pillarEntity.putStack(playerEntity.getStackInHand(hand)));
		}
	}
	return ActionResult.SUCCESS;
}
 
@Inject(method = "interactBlock", at = @At(
        value = "RETURN",
        ordinal = 2
))
private void onBlockActivated(PlayerEntity playerArg, World world, ItemStack stack, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable<ActionResult> cir)
{
    PLAYER_INTERACTS_WITH_BLOCK.onBlockHit(player, hand, blockHitResult);
}
 
@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());
    }
}
 
@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);
    }
}
 
源代码27 项目: EnderStorage   文件: ItemEnderPouch.java
@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);
}
 
源代码28 项目: fabric-carpet   文件: CarpetEventServer.java
@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);
}
 
源代码29 项目: Survivalist   文件: DryingRackBlock.java
@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;
}
 
源代码30 项目: Wurst7   文件: KillauraHack.java
@Override
public void onPostMotion()
{
	if(target == null)
		return;
	
	ClientPlayerEntity player = MC.player;
	MC.interactionManager.attackEntity(player, target);
	player.swingHand(Hand.MAIN_HAND);
	
	target = null;
}
 
 类所在包
 类方法
 同包方法