Instruction class
Пакет: com.hypixel.hytale.server.npc.instructions
Файл: com/hypixel/hytale/server/npc/instructions/Instruction.java
implements: RoleStateChange, IAnnotatedComponentCollection
Поля (13)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
Instruction[] |
EMPTY_ARRAY |
|
|
break |
|
int |
var1 |
|
String |
var1 |
|
InfoProvider |
var10 |
|
UUIDComponent |
var11 |
|
int |
var3 |
|
BodyMotion |
var4 |
|
int |
var5 |
|
BodyMotion |
var5 |
|
DebugSupport |
var6 |
|
boolean |
var7 |
|
UUIDComponent |
var8 |
Методы (61)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IndexOutOfBoundsExceptionthrow new IndexOutOfBoundsException() |
public |
void |
clearOncevoid clearOnce() |
public |
void |
executevoid execute(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, double var3, @Nonnull Store<EntityStore> var5) |
public |
void |
executeActionsvoid executeActions(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6) |
|
|
for for(int var6 = this.index - 1; var6 >= 0; var6--) |
|
|
for for(Instruction var5 : this.instructionList) |
|
|
for for(int var3 = 0; var3 < this.instructionList.length; var3++) |
|
|
for for(Instruction var9 : this.instructionList) |
|
|
for for(Instruction var5 : this.instructionList) |
|
|
for for(Instruction var6 : this.instructionList) |
|
|
for for(Instruction var8 : this.instructionList) |
protected |
void |
forEachInstructionvoid forEachInstruction(@Nonnull Consumer<Instruction> var1) |
protected |
<T> void |
forEachInstruction<T> void forEachInstruction(@Nonnull BiConsumer<Instruction, T> var1, T var2) |
protected |
<T, U, V> void |
forEachInstruction<T, U, V> void forEachInstruction(@Nonnull QuadConsumer<Instruction, T, U, V> var1, T var2, U var3, V var4) |
public |
Sensor |
getSensorSensor getSensor() |
public |
double |
getWeightdouble getWeight() |
|
|
if if(var3 != null) |
|
|
if if(this.index < 0) |
|
|
if if(this.parent instanceof Instruction var2) |
|
|
if if(var4 != null) |
|
|
if if(var5 != null) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(this.headMotion != null) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(this.headMotion != null) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(this.headMotion != null) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(this.headMotion != null) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(this.headMotion != null) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(this.headMotion != null) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(this.headMotion != null) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(this.headMotion != null) |
|
|
if if(var1 < 1) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(var1 != null) |
|
|
if if(this.bodyMotion != null) |
|
|
if if(this.headMotion != null) |
|
|
if if(var7) |
|
|
if if(!this.treeMode && !this.continueAfter && !this.invertTreeModeResult) |
|
|
if if(var7) |
|
|
if if(var7) |
|
|
if if(this.instructionList.length <= 0) |
|
|
if if(this.headMotion == null && this.bodyMotion == null) |
|
|
if if(this.treeMode || this.invertTreeModeResult) |
|
|
if if(this.treeMode) |
|
|
if if(this.treeMode || this.invertTreeModeResult) |
|
|
if if(this.parentTreeModeStep != null) |
|
|
if if(this.continueAfter == this.invertTreeModeResult) |
|
|
if if(this.treeMode) |
public |
boolean |
isContinueAfterboolean isContinueAfter() |
public |
boolean |
matchesboolean matches(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, double var3, @Nonnull Store<EntityStore> var5) |
public |
void |
notifyChildSensorMatchvoid notifyChildSensorMatch() |
public |
void |
onCompletedvoid onCompleted(@Nonnull ExecutionSupport var1) |
public |
void |
onEndMotionvoid onEndMotion() |
public |
void |
onMatchedvoid onMatched(@Nonnull ExecutionSupport var1) |
public |
void |
resetvoid reset() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.instructions;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.function.consumer.QuadConsumer;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.server.core.entity.UUIDComponent;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.NPCPlugin;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.instructions.builders.BuilderInstruction;
class="kw">import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
class="kw">import com.hypixel.hytale.server.npc.role.support.DebugSupport;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
class="kw">import com.hypixel.hytale.server.npc.util.ComponentInfo;
class="kw">import com.hypixel.hytale.server.npc.util.IAnnotatedComponent;
class="kw">import com.hypixel.hytale.server.npc.util.IAnnotatedComponentCollection;
class="kw">import java.util.function.BiConsumer;
class="kw">import java.util.function.Consumer;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class Instruction class="kw">implements RoleStateChange, IAnnotatedComponentCollection {
class="kw">public class="kw">static class="kw">final Instruction[] EMPTY_ARRAY = new Instruction[0];
class="kw">public class="kw">static class="kw">final HytaleLogger LOGGER = NPCPlugin.get().getLogger();
class="kw">protected IAnnotatedComponent parent;
@Nullable
class="kw">protected class="kw">final String name;
@Nullable
class="kw">protected class="kw">final String tag;
class="kw">protected class="kw">final Sensor sensor;
class="kw">protected int index;
class="kw">protected class="kw">final Instruction[] instructionList;
@Nullable
class="kw">protected class="kw">final BodyMotion bodyMotion;
@Nullable
class="kw">protected class="kw">final HeadMotion headMotion;
@Nonnull
class="kw">protected class="kw">final ActionList actions;
class="kw">protected class="kw">final double weight;
class="kw">protected class="kw">final boolean treeMode;
class="kw">protected class="kw">final boolean invertTreeModeResult;
class="kw">protected boolean continueAfter;
@Nullable
class="kw">protected Instruction parentTreeModeStep;
class="kw">private Instruction(Instruction[] var1, @Nonnull BuilderSupport var2) {
this.tag = null;
this.name = "Root";
this.sensor = Sensor.NULL;
this.instructionList = var1;
this.bodyMotion = null;
this.headMotion = null;
this.actions = ActionList.EMPTY_ACTION_LIST;
this.continueAfter = false;
this.treeMode = false;
this.invertTreeModeResult = false;
this.weight = 1.0;
int var3 = var2.getInstructionSlot(this.name);
var2.putInstruction(var3, this);
}
class="kw">public Instruction(@Nonnull BuilderInstruction var1, Sensor var2, @Nullable Instruction[] var3, @Nonnull BuilderSupport var4) {
this.tag = var1.getTag();
this.name = var1.getName();
this.sensor = var2;
if (var3 != null) {
this.instructionList = var3;
this.bodyMotion = null;
this.headMotion = null;
this.actions = ActionList.EMPTY_ACTION_LIST;
} else {
this.instructionList = EMPTY_ARRAY;
this.bodyMotion = var1.getBodyMotion(var4);
this.headMotion = var1.getHeadMotion(var4);
this.actions = var1.getActionList(var4);
}
this.continueAfter = var1.isContinueAfter();
this.treeMode = var1.isTreeMode();
this.invertTreeModeResult = var1.isInvertTreeModeResult(var4);
this.weight = var1.getChance(var4);
int var5 = var4.getInstructionSlot(this.name);
var4.putInstruction(var5, this);
}
class="kw">public Sensor getSensor() {
class="kw">return this.sensor;
}
@Nullable
class="kw">public String getDebugTag() {
class="kw">return this.tag;
}
class="kw">public double getWeight() {
class="kw">return this.weight;
}
class="kw">public boolean isContinueAfter() {
class="kw">return this.continueAfter;
}
@Nullable
class="kw">public BodyMotion getBodyMotion() {
class="kw">return this.bodyMotion;
}
@Nullable
class="kw">public <T class="kw">extends BodyMotion> T findNearestPrecedingBodyMotion(@Nonnull Class<T> var1) {
if (this.index < 0) {
class="kw">return null;
}
if (this.parent class="kw">instanceof Instruction var2) {
for (int var6 = this.index - 1; var6 >= 0; var6--) {
BodyMotion var4 = var2.instructionList[var6].getBodyMotion();
if (var1.isInstance(var4)) {
class="kw">return var1.cast(var4);
}
if (var4 != null) {
BodyMotion var5 = var4.findWrappedBodyMotion(var1);
if (var5 != null) {
class="kw">return var5;
}
}
}
class="kw">return null;
} else {
class="kw">return null;
}
}
@Nullable
class="kw">public HeadMotion getHeadMotion() {
class="kw">return this.headMotion;
}
@Override
class="kw">public void registerWithSupport(ExecutionSupport var1) {
this.sensor.registerWithSupport(var1);
for (Instruction var5 : this.instructionList) {
var5.registerWithSupport(var1);
}
if (this.bodyMotion != null) {
this.bodyMotion.registerWithSupport(var1);
}
if (this.headMotion != null) {
this.headMotion.registerWithSupport(var1);
}
this.actions.registerWithSupport(var1);
}
@Override
class="kw">public void motionControllerChanged(
@Nullable Ref<EntityStore> var1, @Nonnull NPCEntity var2, MotionController var3, @Nullable ComponentAccessor<EntityStore> var4
) {
this.sensor.motionControllerChanged(var1, var2, var3, var4);
this.forEachInstruction((var3x, var4x) -> var3x.motionControllerChanged(var1, var2, var4x, var4), var3);
if (this.bodyMotion != null) {
this.bodyMotion.motionControllerChanged(var1, var2, var3, var4);
}
if (this.headMotion != null) {
this.headMotion.motionControllerChanged(var1, var2, var3, var4);
}
this.actions.motionControllerChanged(var1, var2, var3, var4);
}
@Override
class="kw">public void loaded(ExecutionSupport var1) {
this.sensor.loaded(var1);
this.forEachInstruction(Instruction::loaded, var1);
if (this.bodyMotion != null) {
this.bodyMotion.loaded(var1);
}
if (this.headMotion != null) {
this.headMotion.loaded(var1);
}
this.actions.loaded(var1);
}
@Override
class="kw">public void spawned(ExecutionSupport var1) {
this.sensor.spawned(var1);
this.forEachInstruction(Instruction::spawned, var1);
if (this.bodyMotion != null) {
this.bodyMotion.spawned(var1);
}
if (this.headMotion != null) {
this.headMotion.spawned(var1);
}
this.actions.spawned(var1);
}
@Override
class="kw">public void unloaded(ExecutionSupport var1) {
this.sensor.unloaded(var1);
this.forEachInstruction(Instruction::unloaded, var1);
if (this.bodyMotion != null) {
this.bodyMotion.unloaded(var1);
}
if (this.headMotion != null) {
this.headMotion.unloaded(var1);
}
this.actions.unloaded(var1);
}
@Override
class="kw">public void removed(ExecutionSupport var1) {
this.sensor.removed(var1);
this.forEachInstruction(Instruction::removed, var1);
if (this.bodyMotion != null) {
this.bodyMotion.removed(var1);
}
if (this.headMotion != null) {
this.headMotion.removed(var1);
}
this.actions.removed(var1);
}
@Override
class="kw">public void teleported(ExecutionSupport var1, World var2, World var3) {
this.sensor.teleported(var1, var2, var3);
this.forEachInstruction(Instruction::teleported, var1, var2, var3);
if (this.bodyMotion != null) {
this.bodyMotion.teleported(var1, var2, var3);
}
if (this.headMotion != null) {
this.headMotion.teleported(var1, var2, var3);
}
this.actions.teleported(var1, var2, var3);
}
@Override
class="kw">public int componentCount() {
int var1 = 1;
var1 += this.actions.actionCount();
var1 += this.instructionList.length;
if (this.bodyMotion != null) {
var1++;
}
if (this.headMotion != null) {
var1++;
}
class="kw">return var1;
}
@Override
class="kw">public IAnnotatedComponent getComponent(int var1) {
if (var1 < 1) {
class="kw">return this.sensor;
}
if (var1 <= this.actions.actionCount()) {
class="kw">return this.actions.getComponent(var1 - 1);
}
if (var1 < this.componentCount()) {
if (this.bodyMotion != null) {
class="kw">return this.headMotion != null && var1 == this.componentCount() - 1 ? this.headMotion : this.bodyMotion;
} else {
class="kw">return this.headMotion != null ? this.headMotion : this.instructionList[var1 - 1];
}
} else {
throw new IndexOutOfBoundsException();
}
}
@Override
class="kw">public void getInfo(ExecutionSupport var1, @Nonnull ComponentInfo var2) {
if (this.name != null && !this.name.isEmpty()) {
var2.addField("Name: " + this.name);
}
}
@Override
class="kw">public IAnnotatedComponent getParent() {
class="kw">return this.parent;
}
@Override
class="kw">public int getIndex() {
class="kw">return this.index;
}
@Nonnull
@Override
class="kw">public String getLabel() {
String var1 = this.getDebugTag();
if (var1 != null) {
class="kw">return var1;
} else {
class="kw">return this.index >= 0 ? String.format("[%s]%s", this.index, this.getClass().getSimpleName()) : this.getClass().getSimpleName();
}
}
@Override
class="kw">public void setContext(IAnnotatedComponent var1, int var2) {
this.parent = var1;
this.index = var2;
this.sensor.setContext(this, -1);
if (this.bodyMotion != null) {
this.bodyMotion.setContext(this, -1);
}
if (this.headMotion != null) {
this.headMotion.setContext(this, -1);
}
this.actions.setContext(this);
for (int var3 = 0; var3 < this.instructionList.length; var3++) {
this.instructionList[var3].setContext(this, var3);
}
}
class="kw">public boolean matches(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, double var3, @Nonnull Store<EntityStore> var5) {
DebugSupport var6 = var2.getDebugSupport();
boolean var7 = var6.isTraceSensorFails();
if (var7) {
var6.setLastFailingSensor(this.sensor);
}
if (this.sensor.matches(var1, var2, var3, var5)) {
if (!this.treeMode && !this.continueAfter && !this.invertTreeModeResult) {
var2.notifySensorMatch();
}
if (var7) {
var6.setLastFailingSensor(null);
}
class="kw">return true;
} else {
if (var6.isTraceFail()) {
UUIDComponent var8 = var5.getComponent(var1, UUIDComponent.getComponentType());
assert var8 != null;
LOGGER.at(Level.INFO).log("Instruction Sensor FAIL uuid=%s, debug=%s", var8.getUuid(), this.getBreadCrumbs());
}
if (var7) {
LOGGER.at(Level.INFO).log("Sensor FAIL, sensor=%s", var6.getLastFailingSensor().getBreadCrumbs());
var6.setLastFailingSensor(null);
}
class="kw">return false;
}
}
class="kw">public void executeActions(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6) {
if (this.actions.canExecute(var1, var2, var3, var4, var6)) {
this.actions.execute(var1, var2, var3, var4, var6);
}
}
class="kw">public void execute(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, double var3, @Nonnull Store<EntityStore> var5) {
if (this.instructionList.length <= 0) {
InfoProvider var10 = this.sensor.getSensorInfo();
if (this.headMotion != null && var2.getMotionContextSupport().setNextHeadMotionStep(this)) {
this.headMotion.preComputeSteering(var1, var2, var10, var5);
}
if (this.bodyMotion != null && var2.getMotionContextSupport().setNextBodyMotionStep(this)) {
this.bodyMotion.preComputeSteering(var1, var2, var10, var5);
}
this.executeActions(var1, var2, var10, var3, var5);
if (this.headMotion == null && this.bodyMotion == null) {
this.sensor.setOnce();
this.sensor.done();
}
if (var2.getDebugSupport().isTraceSuccess()) {
UUIDComponent var11 = var5.getComponent(var1, UUIDComponent.getComponentType());
assert var11 != null;
LOGGER.at(Level.INFO).log("Instruction SUCC uuid=%s, debug=%s", var11.getUuid(), this.getBreadCrumbs());
}
} else {
for (Instruction var9 : this.instructionList) {
if (var9.matches(var1, var2, var3, var5)) {
var9.onMatched(var2);
var9.execute(var1, var2, var3, var5);
var9.onCompleted(var2);
if (!var9.isContinueAfter()) {
break;
}
}
}
this.sensor.setOnce();
this.sensor.done();
}
}
class="kw">public void clearOnce() {
this.sensor.clearOnce();
this.forEachInstruction(Instruction::clearOnce);
this.actions.clearOnce();
}
class="kw">public void onEndMotion() {
this.actions.onEndMotion();
}
class="kw">public void onMatched(@Nonnull ExecutionSupport var1) {
if (this.treeMode || this.invertTreeModeResult) {
this.parentTreeModeStep = var1.swapTreeModeSteps(this);
if (this.treeMode) {
this.continueAfter = true;
}
}
}
class="kw">public void onCompleted(@Nonnull ExecutionSupport var1) {
if (this.treeMode || this.invertTreeModeResult) {
var1.swapTreeModeSteps(this.parentTreeModeStep);
if (this.parentTreeModeStep != null) {
if (this.continueAfter == this.invertTreeModeResult) {
this.parentTreeModeStep.notifyChildSensorMatch();
}
this.parentTreeModeStep = null;
}
}
}
class="kw">public void notifyChildSensorMatch() {
if (this.treeMode) {
this.continueAfter = false;
}
}
class="kw">public void reset() {
this.clearOnce();
}
class="kw">protected void forEachInstruction(@Nonnull Consumer<Instruction> var1) {
for (Instruction var5 : this.instructionList) {
var1.accept(var5);
}
}
class="kw">protected <T> void forEachInstruction(@Nonnull BiConsumer<Instruction, T> var1, T var2) {
for (Instruction var6 : this.instructionList) {
var1.accept(var6, var2);
}
}
class="kw">protected <T, U, V> void forEachInstruction(@Nonnull QuadConsumer<Instruction, T, U, V> var1, T var2, U var3, V var4) {
for (Instruction var8 : this.instructionList) {
var1.accept(var8, var2, var3, var4);
}
}
@Nonnull
class="kw">public class="kw">static Instruction createRootInstruction(Instruction[] var0, @Nonnull BuilderSupport var1) {
class="kw">return new Instruction(var0, var1);
}
}