ContextualUseNPCInteraction class
Пакет: com.hypixel.hytale.server.npc.interactions
Файл: com/hypixel/hytale/server/npc/interactions/ContextualUseNPCInteraction.java
extends: SimpleInstantInteraction
Поля (6)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
HytaleLogger |
LOGGER |
|
Ref |
var4 |
|
CommandBuffer |
var5 |
|
Ref |
var6 |
|
Player |
var7 |
|
NPCEntity |
var8 |
Методы (4)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
|
if if(var4 == null) |
|
|
if if(var7 == null) |
|
|
if if(var8 == null) |
abstract |
|
super super(var1) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.interactions;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.protocol.InteractionState;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.server.core.entity.EntityUtils;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.SimpleInstantInteraction;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.util.InteractionValidation;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.role.support.StateSupport;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">public class ContextualUseNPCInteraction class="kw">extends SimpleInstantInteraction {
class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<ContextualUseNPCInteraction> CODEC = BuilderCodec.<SimpleInstantInteraction>builder(
ContextualUseNPCInteraction.class, ContextualUseNPCInteraction::new, SimpleInstantInteraction.CODEC
)
.documentation("Interacts with the target NPC passing in context for it to use.")
.<String>appendInherited(
new KeyedCodec<>("Context", Codec.STRING), (var0, var1) -> var0.context = var1, var0 -> var0.context, (var0, var1) -> var0.context = var1.context
)
.documentation("The provided context for the use action.")
.addValidator(Validators.nonNull())
.add()
.build();
class="kw">protected String context;
class="kw">public ContextualUseNPCInteraction(String var1) {
super(var1);
}
class="kw">protected ContextualUseNPCInteraction() {
}
@Override
class="kw">protected class="kw">final void firstRun(@Nonnull InteractionType var1, @Nonnull InteractionContext var2, @Nonnull CooldownHandler var3) {
Ref var4 = var2.getTargetEntity();
if (var4 == null) {
var2.getState().state = InteractionState.Failed;
} else {
CommandBuffer var5 = var2.getCommandBuffer();
Ref var6 = var2.getEntity();
Player var7 = var5.getComponent(var6, Player.getComponentType());
if (var7 == null) {
HytaleLogger.getLogger().at(Level.INFO).log("UseNPCInteraction requires a Player but was used for: %s", var6);
var2.getState().state = InteractionState.Failed;
} else if (!InteractionValidation.canPlayerInteractWithEntity(var2.getEntity(), var5, var2.getHeldItem(), var4)) {
LOGGER.at(Level.WARNING)
.log("%s failed use NPC interaction distance check for target entity %d", EntityUtils.getEntityName(var2.getEntity(), var5), var4.getIndex());
var2.getState().state = InteractionState.Failed;
} else {
NPCEntity var8 = var5.getComponent(var4, NPCEntity.getComponentType());
if (var8 == null) {
HytaleLogger.getLogger().at(Level.INFO).log("UseNPCInteraction requires a target NPC");
var2.getState().state = InteractionState.Failed;
} else if (!StateSupport.get(var4, var5).willInteractWith(var6)) {
var2.getState().state = InteractionState.Failed;
} else {
StateSupport.get(var4, var5).addContextualInteraction(var6, this.context);
}
}
}
}
@Nonnull
@Override
class="kw">public String toString() {
class="kw">return "ContextualUseNPCInteraction{} " + super.toString();
}
}