MotionSequence class
Пакет: com.hypixel.hytale.server.npc.corecomponents.utility
Файл: com/hypixel/hytale/server/npc/corecomponents/utility/MotionSequence.java
extends: MotionBase
implements: IAnnotatedComponentCollection
Поля (3)
| Модификаторы | Тип | Имя |
|---|---|---|
|
|
break |
final |
boolean |
looped |
|
Motion |
var8 |
Методы (20)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Motion sequence must have steps!") |
protected |
void |
activateNextvoid activateNext(@Nonnull Ref<EntityStore> var1, int var2, @Nonnull ExecutionSupport var3, @Nonnull ComponentAccessor<EntityStore> var4) |
protected |
void |
doActivatevoid doActivate(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull ComponentAccessor<EntityStore> var3) |
|
|
for for(Motion var5 : this.steps) |
|
|
for for(Motion var8 : this.steps) |
|
|
for for(Motion var5 : this.steps) |
|
|
for for(Motion var5 : this.steps) |
|
|
for for(Motion var5 : this.steps) |
|
|
for for(Motion var5 : this.steps) |
|
|
for for(Motion var7 : this.steps) |
|
|
for for(int var3 = 0; var3 < this.steps.length; var3++) |
|
|
if if(this.restartOnActivate) |
|
|
if if(!this.finished) |
|
|
if if(this.activeMotion != null) |
|
|
if if(this.finished) |
|
|
if if(this.index + 1 < this.steps.length) |
|
|
if if(!this.looped) |
|
|
if if(this.steps.length == 0) |
|
|
if if(this.index >= 0 && this.index < this.steps.length) |
public |
void |
restartvoid restart() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.corecomponents.utility;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
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.corecomponents.MotionBase;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.utility.builders.BuilderMotionSequence;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import com.hypixel.hytale.server.npc.instructions.Motion;
class="kw">import com.hypixel.hytale.server.npc.movement.Steering;
class="kw">import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
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.Objects;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class="kw">abstract class MotionSequence<T class="kw">extends Motion> class="kw">extends MotionBase class="kw">implements IAnnotatedComponentCollection {
class="kw">protected class="kw">final boolean looped;
class="kw">protected class="kw">final boolean restartOnActivate;
class="kw">protected class="kw">final T[] steps;
class="kw">protected boolean finished;
class="kw">protected int index;
@Nullable
class="kw">protected T activeMotion;
class="kw">public MotionSequence(@Nonnull BuilderMotionSequence<T> var1, T[] var2) {
this.restart();
this.looped = var1.isLooped();
this.restartOnActivate = var1.isRestartOnActivate();
this.steps = var2;
}
@Override
class="kw">public void activate(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull ComponentAccessor<EntityStore> var3) {
if (this.restartOnActivate) {
this.deactivate(var1, var2, var3);
this.restart();
}
if (!this.finished) {
this.doActivate(var1, var2, var3);
}
}
@Override
class="kw">public void deactivate(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull ComponentAccessor<EntityStore> var3) {
if (this.activeMotion != null) {
this.activeMotion.deactivate(var1, var2, var3);
this.activeMotion = null;
}
}
@Override
class="kw">public boolean computeSteering(
@Nonnull Ref<EntityStore> var1,
@Nonnull ExecutionSupport var2,
@Nullable InfoProvider var3,
double var4,
@Nonnull Steering var6,
@Nonnull ComponentAccessor<EntityStore> var7
) {
if (this.finished) {
var6.clear();
class="kw">return false;
}
Motion var8 = this.activeMotion;
do {
Objects.requireNonNull(this.activeMotion, "Active motion not set");
if (this.activeMotion.computeSteering(var1, var2, var3, var4, var6, var7)) {
class="kw">return true;
}
if (this.index + 1 < this.steps.length) {
this.activateNext(var1, this.index + 1, var2, var7);
} else {
if (!this.looped) {
break;
}
this.activateNext(var1, 0, var2, var7);
}
} while (this.activeMotion != var8);
this.deactivate(var1, var2, var7);
this.finished = true;
class="kw">return false;
}
@Override
class="kw">public void registerWithSupport(ExecutionSupport var1) {
for (Motion var5 : this.steps) {
var5.registerWithSupport(var1);
}
}
@Override
class="kw">public void motionControllerChanged(
@Nullable Ref<EntityStore> var1, @Nonnull NPCEntity var2, MotionController var3, @Nullable ComponentAccessor<EntityStore> var4
) {
for (Motion var8 : this.steps) {
var8.motionControllerChanged(var1, var2, var3, var4);
}
}
@Override
class="kw">public void loaded(ExecutionSupport var1) {
for (Motion var5 : this.steps) {
var5.loaded(var1);
}
}
@Override
class="kw">public void spawned(ExecutionSupport var1) {
for (Motion var5 : this.steps) {
var5.spawned(var1);
}
}
@Override
class="kw">public void unloaded(ExecutionSupport var1) {
for (Motion var5 : this.steps) {
var5.unloaded(var1);
}
}
@Override
class="kw">public void removed(ExecutionSupport var1) {
for (Motion var5 : this.steps) {
var5.removed(var1);
}
}
@Override
class="kw">public void teleported(ExecutionSupport var1, World var2, World var3) {
for (Motion var7 : this.steps) {
var7.teleported(var1, var2, var3);
}
}
@Override
class="kw">public int componentCount() {
class="kw">return this.steps.length;
}
@Override
class="kw">public IAnnotatedComponent getComponent(int var1) {
class="kw">return this.steps[var1];
}
@Override
class="kw">public void setContext(IAnnotatedComponent var1, int var2) {
for (int var3 = 0; var3 < this.steps.length; var3++) {
this.steps[var3].setContext(var1, var3);
}
}
class="kw">public void restart() {
this.index = 0;
this.finished = false;
}
class="kw">protected void doActivate(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull ComponentAccessor<EntityStore> var3) {
if (this.steps.length == 0) {
throw new IllegalArgumentException("Motion sequence must have steps!");
}
if (this.index >= 0 && this.index < this.steps.length) {
this.activeMotion = this.steps[this.index];
Objects.requireNonNull(this.activeMotion, "Active motion must not be null");
this.activeMotion.activate(var1, var2, var3);
} else {
throw new IndexOutOfBoundsException(
String.format("Motion sequence index out of range (%s) must be less than size (%s)", this.index, this.steps.length)
);
}
}
class="kw">protected void activateNext(@Nonnull Ref<EntityStore> var1, int var2, @Nonnull ExecutionSupport var3, @Nonnull ComponentAccessor<EntityStore> var4) {
this.activeMotion.deactivate(var1, var3, var4);
this.index = var2;
this.doActivate(var1, var3, var4);
}
}