use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityAnimation in project LanternServer by LanternPowered.
the class PlayerInteractionHandler method handleItemInteraction.
public void handleItemInteraction(MessagePlayInPlayerUseItem message) {
// Prevent duplicate messages
final long time = System.currentTimeMillis();
if (this.lastInteractionTime != -1L && time - this.lastInteractionTime < 40) {
return;
}
this.lastInteractionTime = time;
final CauseStack causeStack = CauseStack.current();
try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
final BehaviorContextImpl context = new BehaviorContextImpl(causeStack);
frame.pushCause(this.player);
frame.addContext(ContextKeys.PLAYER, this.player);
final BehaviorContext.Snapshot snapshot = context.pushSnapshot();
if (!handleItemInteraction(context, snapshot)) {
if (!this.player.get(LanternKeys.CAN_DUAL_WIELD).orElse(false)) {
return;
}
final AbstractSlot offHandSlot = this.player.getInventory().getOffhand();
final Optional<ItemStack> handItem = offHandSlot.peek();
if (handItem.isPresent()) {
final DualWieldProperty property = handItem.get().getProperty(DualWieldProperty.class).orElse(null);
// noinspection ConstantConditions
if (property != null && property.getValue()) {
/*
final Vector3d position = this.player.getPosition().add(0, this.player.get(Keys.IS_SNEAKING).get() ? 1.54 : 1.62, 0);
final Optional<BlockRayHit<LanternWorld>> hit = BlockRay.from(this.player.getWorld(), position)
.direction(this.player.getDirectionVector())
.distanceLimit(5)
// Is this supposed to be inverted?
.skipFilter(Predicates.not(BlockRay.onlyAirFilter()))
.build()
.end();
if (hit.isPresent() && hit.get().getLocation().getBlock().getType() != BlockTypes.AIR) {
return;
}
*/
this.player.getConnection().send(new MessagePlayOutEntityAnimation(this.player.getNetworkId(), 3));
this.player.triggerEvent(SwingHandEntityEvent.of(HandTypes.OFF_HAND));
/*
final CooldownTracker cooldownTracker = this.player.getCooldownTracker();
cooldownTracker.set(handItem.get().getType(), 15);
*/
}
}
}
}
}
Aggregations