當前位置: 首頁>>代碼示例>>Java>>正文


Java ForgeHooks.onRightClickBlock方法代碼示例

本文整理匯總了Java中net.minecraftforge.common.ForgeHooks.onRightClickBlock方法的典型用法代碼示例。如果您正苦於以下問題:Java ForgeHooks.onRightClickBlock方法的具體用法?Java ForgeHooks.onRightClickBlock怎麽用?Java ForgeHooks.onRightClickBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraftforge.common.ForgeHooks的用法示例。


在下文中一共展示了ForgeHooks.onRightClickBlock方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: work

import net.minecraftforge.common.ForgeHooks; //導入方法依賴的package包/類
@Override
public float work() {
    if (WorkUtils.isDisabled(this.getBlockType())) return 0;
    if (ItemStackUtils.isInventoryFull(outItems)) return 0;
    hasWorked = false;
    List<BlockPos> blockPos = BlockUtils.getBlockPosInAABB(getWorkingArea());
    if (pointer >= blockPos.size()) pointer = 0;
    if (pointer < blockPos.size() && BlockUtils.canBlockBeBroken(this.world, blockPos.get(pointer))) {
        BlockPos pos = blockPos.get(pointer);
        if (this.world.getBlockState(pos).getBlock() instanceof IGrowable) {
            FakePlayer player = IndustrialForegoing.getFakePlayer(this.world, pos.up());
            player.inventory.clear();
            WORKING_TILES.add(this);
            this.world.getBlockState(pos).getBlock().onBlockActivated(this.world, pos, this.world.getBlockState(pos), player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
            ForgeHooks.onRightClickBlock(player, EnumHand.MAIN_HAND, pos, EnumFacing.UP, new Vec3d(0, 0, 0));
            for (ItemStack stack : player.inventory.mainInventory) {
                if (!stack.isEmpty()) {
                    ItemHandlerHelper.insertItem(outItems, stack, false);
                    sludge.fill(new FluidStack(FluidsRegistry.SLUDGE, 10 * stack.getCount()), true);
                    hasWorked = true;
                }
            }
            player.inventory.clear();
            WORKING_TILES.remove(this);
        }
    }
    ++pointer;
    return hasWorked ? 1 : 0.1f;
}
 
開發者ID:Buuz135,項目名稱:Industrial-Foregoing,代碼行數:30,代碼來源:PlantInteractorTile.java

示例2: rightClick

import net.minecraftforge.common.ForgeHooks; //導入方法依賴的package包/類
private boolean rightClick(BlockPos pos) {
    EnumFacing faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
    EntityPlayer player = drone.getFakePlayer();
    World world = drone.world();
    ItemStack stack = player.getHeldItemMainhand();

    player.setPosition(pos.getX() + 0.5, pos.getY() + 0.5 - player.eyeHeight, pos.getZ() + 0.5);
    player.rotationPitch = faceDir.getFrontOffsetY() * -90;
    player.rotationYaw = PneumaticCraftUtils.getYawFromFacing(faceDir);

    float hitX = (float)(player.posX - pos.getX());
    float hitY = (float)(player.posY - pos.getY());
    float hitZ = (float)(player.posZ - pos.getZ());

    // this is adapted from PlayerInteractionManager#processRightClickBlock()
    try {
        PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(player, EnumHand.MAIN_HAND, pos, faceDir.getOpposite(),  ForgeHooks.rayTraceEyeHitVec(player, 2.0D));
        if (event.isCanceled() || event.getUseItem() == Event.Result.DENY) {
            return false;
        }

        EnumActionResult ret = stack.onItemUseFirst(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
        if (ret != EnumActionResult.PASS) return false;

        boolean bypass = player.getHeldItemMainhand().doesSneakBypassUse(world, pos, player);
        EnumActionResult result = EnumActionResult.PASS;

        if (!player.isSneaking() || bypass || event.getUseBlock() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            IBlockState iblockstate = world.getBlockState(pos);
            if(event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
                if (iblockstate.getBlock().onBlockActivated(world, pos, iblockstate, player, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ)) {
                    result = EnumActionResult.SUCCESS;
                }
        }

        if (stack.isEmpty() || player.getCooldownTracker().hasCooldown(stack.getItem())) {
            return false;
        }

        if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock()) {
            Block block = ((ItemBlock)stack.getItem()).getBlock();
            if (block instanceof BlockCommandBlock || block instanceof BlockStructure) {
                return false;
            }
        }

        if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
                || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            ItemStack copyBeforeUse = stack.copy();
            result = stack.onItemUse(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
            if (result == EnumActionResult.PASS) {
                ActionResult<ItemStack> rightClickResult = stack.getItem().onItemRightClick(world, player, EnumHand.MAIN_HAND);
                player.setHeldItem(EnumHand.MAIN_HAND, rightClickResult.getResult());
            }
            if (player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) {
                net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, EnumHand.MAIN_HAND);
            }
        }

        return false;
    } catch (Throwable e) {
        Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:67,代碼來源:DroneAIBlockInteract.java

示例3: doUseAction

import net.minecraftforge.common.ForgeHooks; //導入方法依賴的package包/類
private EnumActionResult doUseAction(final World fakeWorld, final EntityPlayer realPlayer, final EntityPlayer fakePlayer,
        final BlockPos posCenter, final EnumFacing side, final Vec3d hitPos, final EnumHand hand,
        final float hitX, final float hitY, final float hitZ)
{
    ItemStack stack = realPlayer.getHeldItem(hand);

    if (stack.isEmpty() == false)
    {
        ResourceLocation regName = stack.getItem().getRegistryName();

        if (this.isItemAllowedForPreviewing(regName) == false)
        {
            return EnumActionResult.PASS;
        }

        fakePlayer.setLocationAndAngles(realPlayer.posX, realPlayer.posY, realPlayer.posZ, realPlayer.rotationYaw, realPlayer.rotationPitch);

        ItemStack stackCopy = stack.copy();
        // A second copy, to which to reset after the fake use action has been completed.
        // This prevents the fake use from happening again every tick if the only item from the fake player's hand was consumed.
        ItemStack stackCopy2 = stack.copy();
        fakePlayer.setHeldItem(hand, stackCopy);

        try
        {
            PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(
                    fakePlayer, hand, posCenter, side, ForgeHooks.rayTraceEyeHitVec(fakePlayer, 6));

            if (event.isCanceled())
            {
                return EnumActionResult.PASS;
            }

            EnumActionResult result = stackCopy.onItemUseFirst(fakePlayer, fakeWorld, posCenter, hand, side, hitX, hitY, hitZ);
            if (result == EnumActionResult.SUCCESS)
            {
                fakePlayer.setHeldItem(hand, stackCopy2);
                return result;
            }

            result = stackCopy.onItemUse(fakePlayer, fakeWorld, posCenter, hand, side, hitX, hitY, hitZ);
            if (result == EnumActionResult.SUCCESS)
            {
                fakePlayer.setHeldItem(hand, stackCopy2);
                return result;
            }

            result = stackCopy.useItemRightClick(fakeWorld, fakePlayer, hand).getType();
            if (result == EnumActionResult.SUCCESS)
            {
                fakePlayer.setHeldItem(hand, stackCopy2);
                return result;
            }
        }
        catch (Throwable t)
        {
            if (Configs.enableVerboseLogging)
            {
                PlacementPreview.logger.warn("Item '{}' threw an exception while trying to fake use it," +
                    " blacklisting it for this session\n", regName, t);
            }
            else
            {
                PlacementPreview.logger.warn("Item '{}' threw an exception while trying to fake use it," +
                    " blacklisting it for this session\n", regName);
            }

            fakePlayer.setHeldItem(hand, stackCopy2);
            this.blacklistedItems.add(regName);
            this.whitelistedItems.remove(regName);
        }
    }

    return EnumActionResult.PASS;
}
 
開發者ID:maruohon,項目名稱:placementpreview,代碼行數:76,代碼來源:TickHandler.java


注:本文中的net.minecraftforge.common.ForgeHooks.onRightClickBlock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。