• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java HandType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spongepowered.api.data.type.HandType的典型用法代码示例。如果您正苦于以下问题:Java HandType类的具体用法?Java HandType怎么用?Java HandType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HandType类属于org.spongepowered.api.data.type包,在下文中一共展示了HandType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onItemUse

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Override
public boolean onItemUse(ItemStack itemStack, Player player, HandType currHand, BlockSnapshot clickedBlock,
        Direction side, Vector3d hitPoint) {
    CustomWorld world = WorldManager.toCustomWorld(player.getWorld());
    Vector3d pos;
    if (hitPoint == null) {
        pos = clickedBlock.getPosition().add(side.asBlockOffset()).toDouble().add(0.5, 0, 0.5);
    } else {
        pos = clickedBlock.getPosition().toDouble().add(hitPoint);
    }
    TurtleEntity turtle = new TurtleEntity(player.getWorld());
    turtle.setPosition(pos);
    Vector3d r = player.getHeadRotation();
    turtle.setRotation(new Vector3d(r.getX(), r.getY() + 180, r.getZ()));
    if (world.spawnEntity(turtle)) {
        if (player.gameMode().get() != GameModes.CREATIVE) {
            itemStack.setQuantity(itemStack.getQuantity() - 1);
            if (itemStack.getQuantity() == 0) {
                itemStack = null;
            }
            player.setItemInHand(currHand, itemStack);
        }
    }
    return false;
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:26,代码来源:ItemTurtle.java


示例2: handleFinishItemInteraction0

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
private void handleFinishItemInteraction0(AbstractSlot slot, HandType handType) {
    final Optional<ItemStack> handItem = slot.peek();
    if (handItem.isPresent()) {
        final CauseStack causeStack = CauseStack.current();
        try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
            frame.pushCause(this.player);
            frame.addContext(ContextKeys.PLAYER, this.player);
            if (handItem.isPresent()) {
                final LanternItemType itemType = (LanternItemType) handItem.get().getType();
                frame.addContext(ContextKeys.USED_ITEM_STACK, handItem.get());
                frame.addContext(ContextKeys.USED_SLOT, slot);
                frame.addContext(ContextKeys.INTERACTION_HAND, handType);
                frame.addContext(ContextKeys.ITEM_TYPE, itemType);

                final BehaviorContextImpl context = new BehaviorContextImpl(causeStack);
                if (context.process(itemType.getPipeline().pipeline(FinishUsingItemBehavior.class),
                        (ctx, behavior) -> behavior.tryUse(itemType.getPipeline(), ctx)).isSuccess()) {
                    context.accept();
                }
            }
        }
    }
    resetItemUseTime();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:PlayerInteractionHandler.java


示例3: handleHandItemInteraction

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
private boolean handleHandItemInteraction(BehaviorContextImpl context, HandType handType, AbstractSlot slot,
        @Nullable BehaviorContext.Snapshot snapshot) {
    final Optional<HandType> activeHand = this.player.get(LanternKeys.ACTIVE_HAND).orElse(Optional.empty());
    // The player is already interacting
    if (activeHand.isPresent()) {
        return true;
    }
    final Optional<ItemStack> handItem = slot.peek();
    if (handItem.isPresent()) {
        final LanternItemType itemType = (LanternItemType) handItem.get().getType();
        context.addContext(ContextKeys.USED_ITEM_STACK, handItem.get());
        context.addContext(ContextKeys.USED_SLOT, slot);
        context.addContext(ContextKeys.INTERACTION_HAND, handType);
        context.addContext(ContextKeys.ITEM_TYPE, itemType);

        final BehaviorResult result = context.process(itemType.getPipeline().pipeline(InteractWithItemBehavior.class),
                (ctx, behavior) -> behavior.tryInteract(itemType.getPipeline(), ctx));
        if (result.isSuccess()) {
            return true;
        }
        if (snapshot != null) {
            context.popSnapshot(snapshot);
        }
    }
    return false;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:27,代码来源:PlayerInteractionHandler.java


示例4: handleEvent

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Override
protected void handleEvent(EntityProtocolUpdateContext context, EntityEvent event) {
    if (event instanceof DamagedEntityEvent) {
        context.sendToAll(() -> new MessagePlayOutEntityAnimation(getRootEntityId(), 1));
    } else if (event instanceof SwingHandEntityEvent) {
        final HandType handType = ((SwingHandEntityEvent) event).getHandType();
        if (handType == HandTypes.MAIN_HAND) {
            context.sendToAllExceptSelf(() -> new MessagePlayOutEntityAnimation(getRootEntityId(), 0));
        } else if (handType == HandTypes.OFF_HAND) {
            context.sendToAllExceptSelf(() -> new MessagePlayOutEntityAnimation(getRootEntityId(), 3));
        } else {
            super.handleEvent(context, event);
        }
    } else {
        super.handleEvent(context, event);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:LivingEntityProtocol.java


示例5: decode

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Override
public MessagePlayInUseEntity decode(CodecContext context, ByteBuffer buf) throws CodecException {
    final int entityId = buf.readVarInt();
    final int action = buf.readVarInt();
    if (action == 1) {
        return new MessagePlayInUseEntity.Attack(entityId);
    } else if (action == 0 || action == 2) {
        Vector3d position = null;
        if (action == 2) {
            final double x = buf.readFloat();
            final double y = buf.readFloat();
            final double z = buf.readFloat();
            position = new Vector3d(x, y, z);
        }
        final HandType hand = buf.readVarInt() == 0 ? HandTypes.MAIN_HAND : HandTypes.OFF_HAND;
        return new MessagePlayInUseEntity.Interact(entityId, hand, position);
    } else {
        throw new DecoderException("Received a UseEntity message with a unknown action: " + action);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:21,代码来源:CodecPlayInUseEntity.java


示例6: onEntityActivated

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Override
public void onEntityActivated(Entity entity, Player player, HandType currHand) {
    if (ItemWrench.isPlayerUsing(player, currHand)) {
        // TODO code editor
    } else {
    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:8,代码来源:TurtleEntity.java


示例7: onEntityHit

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Override
public void onEntityHit(Entity entity, Player player, HandType currHand) {
    remove();
    Optional<String> dropRule = this.world.getGameRule("doEntityDrops");
    if (player.gameMode().get() != GameModes.CREATIVE && (!dropRule.isPresent()
            || Boolean.parseBoolean(dropRule.get()))) {
        dropAsItem();
    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:10,代码来源:TurtleEntity.java


示例8: onEntityInteract

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Listener
public void onEntityInteract(InteractEntityEvent event, @First Player player) {
    HandType hand = Utils.getEventHand(event);
    CustomWorld world = WorldManager.toCustomWorld(event.getTargetEntity().getWorld());
    EntityTracker tracker = world.getEntityTracker(event.getTargetEntity());
    if (tracker == null) {
        return;
    }
    if (event instanceof InteractEntityEvent.Primary) {
        tracker.onEntityHit(event.getTargetEntity(), player, hand);
    } else if (event instanceof InteractEntityEvent.Secondary) {
        tracker.onEntityActivated(event.getTargetEntity(), player, hand);
    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:15,代码来源:EntityEventListeners.java


示例9: onBlockInteract

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Listener
public void onBlockInteract(InteractBlockEvent.Secondary event, @First Player player) {
    HandType hand = Utils.getEventHand(event);
    Optional<ItemStack> opItem = player.getItemInHand(hand);
    if (!opItem.isPresent() || !CustomItem.isCustomItem(opItem.get())) {
        return;
    }
    boolean useResult = CustomItem.fromItemStack(opItem.get()).onItemUse(opItem.get(), player, hand,
            event.getTargetBlock(), event.getTargetSide(), event.getInteractionPoint().orElse(null));
    event.setCancelled(useResult);
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:12,代码来源:CustomItemEventListeners.java


示例10: isPlayerUsing

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
public static boolean isPlayerUsing(Player player, HandType currHand) {
    Optional<ItemStack> opItem = player.getItemInHand(currHand);
    if (!opItem.isPresent()) {
        return false;
    }
    CustomItem item = CustomItem.fromItemStack(opItem.get());
    return item == ItemRegistry.get("wrench");
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:9,代码来源:ItemWrench.java


示例11: onBlockHit

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Override
public boolean onBlockHit(CustomWorld world, Vector3i pos, Player player, HandType currHand, Direction side,
        Vector3d clickPoint) {
    Cause breakCause = Cause.builder()
            .named("plugin", Industrialization.toContainer())
            .named(NamedCause.SOURCE, player)
            .build();
    world.getWorld().setBlockType(pos, BlockTypes.AIR, BlockChangeFlag.ALL, breakCause);
    // Sponge broke and doesn't fire the event (SpongeCommon#998)
    BlockSnapshot from = world.getWorld().createSnapshot(pos);
    BlockSnapshot to = from.withState(BlockTypes.AIR.getDefaultState());
    List<Transaction<BlockSnapshot>> tr = Lists.newArrayList(new Transaction<>(from, to));
    Sponge.getEventManager().post(SpongeEventFactory.createChangeBlockEventBreak(breakCause, tr));
    return false;
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:16,代码来源:PipeBlock.java


示例12: onBlockActivated

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Override
public boolean onBlockActivated(CustomWorld world, Vector3i pos, Player player, HandType currHand, Direction side,
        Vector3d clickPoint) {
    TileAutoCrafting te = (TileAutoCrafting) world.getBlockData(pos);
    Optional<Container> optContainer = player.openInventory(
            te.getInventory().getAPIInventory(), Cause.source(this).notifier(player).build());
    if (optContainer.isPresent()) {
        te.addContainer(optContainer.get());
    }
    return false;
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:12,代码来源:AutoCraftingBench.java


示例13: onBlockInteract

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Listener
public void onBlockInteract(InteractBlockEvent event, @First Player player) {
    HandType hand = Utils.getEventHand(event);
    BlockSnapshot blockSnapshot = event.getTargetBlock();
    if (blockSnapshot == BlockSnapshot.NONE) {
        return;
    }
    CustomWorld world = WorldManager.toCustomWorld(player.getWorld());
    Vector3i pos = blockSnapshot.getPosition();
    BlockNature block = world.getBlock(pos);
    if (block == null) {
        return;
    }
    Direction side = event.getTargetSide();
    Vector3d point = event.getInteractionPoint().orElse(null);
    boolean allowInteract = !event.isCancelled();
    if (event instanceof InteractBlockEvent.Primary) {
        allowInteract = block.onBlockHit(world, pos, player, hand, side, point);
    } else if (event instanceof InteractBlockEvent.Secondary) {
        if (player.getItemInHand(hand).isPresent() && player.get(Keys.IS_SNEAKING).get()) {
            // Pass on the item click without telling the block
            allowInteract = true;
        } else {
            allowInteract = block.onBlockActivated(world, pos, player, hand, side, point);
        }
    }
    event.setCancelled(!allowInteract);

}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:30,代码来源:CustomBlockEventListeners.java


示例14: getEventHand

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
public static HandType getEventHand(InteractEvent event) {
    HandType hand;
    if (event instanceof InteractBlockEvent.Primary.OffHand) {
        hand = HandTypes.OFF_HAND;
    } else if (event instanceof InteractBlockEvent.Secondary.OffHand) {
        hand = HandTypes.OFF_HAND;
    } else if (event instanceof InteractEntityEvent.Primary.OffHand) {
        hand = HandTypes.OFF_HAND;
    } else if (event instanceof InteractEntityEvent.Secondary.OffHand) {
        hand = HandTypes.OFF_HAND;
    } else {
        hand = HandTypes.MAIN_HAND;
    }
    return hand;
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:16,代码来源:Utils.java


示例15: pulse

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
/**
 * Pulses the interaction handler.
 */
void pulse() {
    if (this.diggingBlock != null) {
        final int breakState = (int) Math.round(((double) Math.max(0, this.diggingEndTime - System.nanoTime())
                / (double) this.diggingDuration) * 10.0);
        if (this.lastBreakState != breakState) {
            sendBreakUpdate(breakState);
            this.lastBreakState = breakState;
        }
    }
    final HandType activeHand = this.player.get(LanternKeys.ACTIVE_HAND).orElse(Optional.empty()).orElse(null);
    final AbstractSlot slot = activeHand == null ? null : activeHand == HandTypes.MAIN_HAND ?
            this.player.getInventory().getHotbar().getSelectedSlot() : this.player.getInventory().getOffhand();
    // The interaction just started
    if (!Objects.equals(activeHand, this.lastActiveHand)) {
        this.lastActiveHand = activeHand;
        this.lastActiveItemStack = slot == null ? null : slot.getRawItemStack();
    } else if (activeHand != null) {
        if (this.activeHandStartTime == -1L) {
            this.activeHandStartTime = LanternGame.currentTimeTicks();
        }
        final ItemStack itemStack = slot.getRawItemStack();
        if (itemStack == null || this.lastActiveItemStack != itemStack) {
            // Stop the interaction
            resetItemUseTime();
        } else {
            final MaximumUseDurationProperty property = itemStack.getProperty(MaximumUseDurationProperty.class).orElse(null);
            if (property != null) {
                // Check if the interaction reached it's max time
                final long time = LanternGame.currentTimeTicks();
                if (time - this.activeHandStartTime > property.getValue()) {
                    handleFinishItemInteraction0(slot, activeHand);
                }
            }
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:40,代码来源:PlayerInteractionHandler.java


示例16: handleFinishItemInteraction

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
public void handleFinishItemInteraction(MessagePlayInOutFinishUsingItem message) {
    final Optional<HandType> activeHand = this.player.get(LanternKeys.ACTIVE_HAND).orElse(Optional.empty());
    // The player is already interacting
    if (!activeHand.isPresent() || this.activeHandStartTime == -1L) {
        return;
    }

    // Try the action of the hotbar item first
    final AbstractSlot slot = activeHand.get() == HandTypes.MAIN_HAND ?
            this.player.getInventory().getHotbar().getSelectedSlot() : this.player.getInventory().getOffhand();

    final ItemStack rawItemStack = slot.getRawItemStack();
    if (rawItemStack == null) {
        return;
    }

    // Require a minimum amount of ticks for the interaction to succeed
    final MinimumUseDurationProperty property = rawItemStack.getProperty(MinimumUseDurationProperty.class).orElse(null);
    if (property != null) {
        final long time = LanternGame.currentTimeTicks();
        if (time - this.activeHandStartTime < property.getValue()) {
            resetItemUseTime();
            return;
        }
    }

    handleFinishItemInteraction0(slot, activeHand.get());
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:29,代码来源:PlayerInteractionHandler.java


示例17: handleItemInteraction

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
private boolean handleItemInteraction(BehaviorContextImpl context, @Nullable BehaviorContext.Snapshot snapshot) {
    final Optional<HandType> activeHand = this.player.get(LanternKeys.ACTIVE_HAND).orElse(Optional.empty());
    if (activeHand.isPresent() || handleMainHandItemInteraction(context, snapshot) || handleOffHandItemInteraction(context, null)) {
        context.accept();
        return true;
    } else {
        context.revert();
        return false;
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:PlayerInteractionHandler.java


示例18: handleEvent

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Override
protected void handleEvent(EntityProtocolUpdateContext context, EntityEvent event) {
    if (event instanceof SwingHandEntityEvent) {
        final HandType handType = ((SwingHandEntityEvent) event).getHandType();
        // Doesn't matter which hand type, just play the swing animation,
        // the golem will use both arms at the same time
        if (handType == HandTypes.MAIN_HAND || handType == HandTypes.OFF_HAND) {
            context.sendToAll(() -> new MessagePlayOutEntityStatus(getRootEntityId(), 4));
        }
    } else {
        super.handleEvent(context, event);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:14,代码来源:IronGolemEntityProcotol.java


示例19: getHandData

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
private byte getHandData() {
    final Optional<HandType> activeHand = this.entity.get(LanternKeys.ACTIVE_HAND).orElse(Optional.empty());
    byte value;
    if (activeHand.isPresent()) {
        value = 0x1;
        if (activeHand.get() == HandTypes.OFF_HAND) {
            value |= 0x2;
        }
    } else {
        value = 0;
    }
    return value;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:14,代码来源:LivingEntityProtocol.java


示例20: decode

import org.spongepowered.api.data.type.HandType; //导入依赖的package包/类
@Override
public MessagePlayInPlayerBlockPlacement decode(CodecContext context, ByteBuffer buf) throws CodecException {
    final Vector3i position = buf.read(Types.VECTOR_3_I);
    final Direction face = fromFace(buf.readVarInt());
    final HandType hand = buf.readVarInt() == 0 ? HandTypes.MAIN_HAND : HandTypes.OFF_HAND;
    final double ox = buf.readFloat();
    final double oy = buf.readFloat();
    final double oz = buf.readFloat();
    final Vector3d offset = new Vector3d(ox, oy, oz);
    return new MessagePlayInPlayerBlockPlacement(position, offset, face, hand);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:12,代码来源:CodecPlayInPlayerBlockPlacement.java



注:本文中的org.spongepowered.api.data.type.HandType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClassPathMapperScanner类代码示例发布时间:2022-05-23
下一篇:
Java MutableServletContextHandler类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap