当前位置: 首页>>代码示例>>Java>>正文


Java HandTypes.MAIN_HAND属性代码示例

本文整理汇总了Java中org.spongepowered.api.data.type.HandTypes.MAIN_HAND属性的典型用法代码示例。如果您正苦于以下问题:Java HandTypes.MAIN_HAND属性的具体用法?Java HandTypes.MAIN_HAND怎么用?Java HandTypes.MAIN_HAND使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.spongepowered.api.data.type.HandTypes的用法示例。


在下文中一共展示了HandTypes.MAIN_HAND属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleEvent

@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,代码行数:17,代码来源:LivingEntityProtocol.java

示例2: decode

@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,代码行数:20,代码来源:CodecPlayInUseEntity.java

示例3: getEventHand

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,代码行数:15,代码来源:Utils.java

示例4: pulse

/**
 * 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,代码行数:39,代码来源:PlayerInteractionHandler.java

示例5: handleFinishItemInteraction

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,代码行数:28,代码来源:PlayerInteractionHandler.java

示例6: handleEvent

@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,代码行数:13,代码来源:IronGolemEntityProcotol.java

示例7: decode

@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,代码行数:11,代码来源:CodecPlayInPlayerBlockPlacement.java

示例8: forHand

public static EquipmentType forHand(HandType handType) {
    checkNotNull(handType, "handType");
    return handType == HandTypes.MAIN_HAND ? EquipmentTypes.MAIN_HAND : EquipmentTypes.OFF_HAND;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:EquipmentTypeRegistryModule.java

示例9: of

public static SwingHandEntityEvent of(HandType handType) {
    checkNotNull(handType, "handType");
    return handType == HandTypes.MAIN_HAND ? Holder.MAIN_HAND :
            handType == HandTypes.OFF_HAND ? Holder.OFF_HAND : new SwingHandEntityEvent(handType);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:SwingHandEntityEvent.java

示例10: decode

@Override
public MessagePlayInPlayerUseItem decode(CodecContext context, ByteBuffer buf) throws CodecException {
    return new MessagePlayInPlayerUseItem(buf.readVarInt() == 0 ? HandTypes.MAIN_HAND : HandTypes.OFF_HAND);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:CodecPlayInPlayerUseItem.java

示例11: decode

@Override
public MessagePlayInPlayerSwingArm decode(CodecContext context, ByteBuffer buf) throws CodecException {
    return new MessagePlayInPlayerSwingArm(buf.readVarInt() == 0 ? HandTypes.MAIN_HAND : HandTypes.OFF_HAND);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:CodecPlayInPlayerSwingArm.java


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