ActionForEach class
Пакет: com.hypixel.hytale.server.npc.corecomponents.utility
Файл: com/hypixel/hytale/server/npc/corecomponents/utility/ActionForEach.java
extends: ActionSequence
Поля (13)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
HytaleLogger |
LOGGER |
|
|
return |
|
|
return |
|
int |
var10 |
|
int |
var12 |
|
int[] |
var3 |
|
IPositionProvider |
var7 |
|
IPositionProvider |
var7 |
|
Ref |
var8 |
|
int |
var8 |
|
|
var8 |
|
int |
var9 |
|
UUIDComponent |
var9 |
Методы (47)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
private |
int |
claimFreeSlotint claimFreeSlot() |
|
|
for for(int var4 = 0; var4 < this.maxTargets; var4++) |
|
|
for for(int var11 = 0; var11 < var10; var11++) |
|
|
for for(int var13 = 0; var13 < var12; var13++) |
|
|
for for(int var1 = 0; var1 < this.pool.length; var1++) |
|
|
for for(int var1 = 0; var1 < this.pool.length; var1++) |
|
|
for for(ActionList var4 : this.pool) |
|
|
for for(ActionList var5 : this.pool) |
|
|
for for(ActionList var8 : this.pool) |
|
|
for for(ActionList var5 : this.pool) |
|
|
for for(ActionList var5 : this.pool) |
|
|
for for(ActionList var5 : this.pool) |
|
|
for for(ActionList var5 : this.pool) |
|
|
for for(ActionList var7 : this.pool) |
|
|
for for(ActionList var4 : this.pool) |
|
|
for for(ActionList var6 : this.pool) |
|
|
if if(this.maxTargetCount > 0) |
|
|
if if(this.minTargetCount < 1) |
|
|
if if(this.maxTargetCount > this.maxTargets) |
|
|
if if(this.isolatePerTarget) |
|
|
if if(this.once && this.triggered) |
|
|
if if(var7 == null) |
|
|
if if(this.isolatePerTarget) |
|
|
if if(var7 instanceof IPositionSet var8) |
|
|
if if(this.sampledIndices != null) |
|
|
if if(this.isolatePerTarget) |
|
|
if if(this.isolatePerTarget && var8 != null) |
|
|
if if(var9 != null) |
|
|
if if(this.clearOncePerTarget) |
|
|
if if(var8 < 0) |
|
|
if if(var8 < 0) |
|
|
if if(this.slotUuid[var1] == null) |
|
|
if if(this.pool != null) |
|
|
if if(this.pool != null) |
|
|
if if(this.pool != null) |
|
|
if if(this.pool != null) |
|
|
if if(this.pool != null) |
|
|
if if(this.pool != null) |
|
|
if if(this.pool != null) |
|
|
if if(this.pool != null) |
|
|
if if(this.pool != null) |
|
|
if if(this.pool != null) |
private |
void |
releaseUnusedSlotsvoid releaseUnusedSlots() |
private |
void |
runForElementvoid runForElement(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull IPositionSet var3, int var4, double var5, @Nonnull Store<EntityStore> var7) |
private |
void |
runIsolatedvoid runIsolated(@Nonnull Ref<EntityStore> var1,
@Nonnull ExecutionSupport var2,
@Nonnull InfoProvider var3,
@Nonnull UUID var4,
double var5,
@Nonnull Store<EntityStore> var7) |
private |
void |
runSharedvoid runShared(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nullable InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6) |
abstract |
|
super super(var1, var2) |
Исходный код
Показать/скрыть
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.component.Store;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.random.RandomExtra;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
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.asset.builder.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.utility.builders.BuilderActionForEach;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.instructions.ActionList;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.IPositionProvider;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.IPositionSet;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.ScopedPositionProvider;
class="kw">import com.hypixel.hytale.server.npc.util.IAnnotatedComponent;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntMap;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
class="kw">import java.util.Arrays;
class="kw">import java.util.UUID;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">public class ActionForEach class="kw">extends ActionSequence {
class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
class="kw">protected class="kw">final int maxTargets;
class="kw">protected class="kw">final int minTargetCount;
class="kw">protected class="kw">final int maxTargetCount;
class="kw">protected class="kw">final boolean clearOncePerTarget;
class="kw">protected class="kw">final boolean isolatePerTarget;
class="kw">private class="kw">final ScopedPositionProvider perScoped = new ScopedPositionProvider();
class="kw">private class="kw">final Vector3d scratch = new Vector3d();
class="kw">private class="kw">final Rotation3f scratchRot = new Rotation3f();
@Nullable
class="kw">private class="kw">final int[] sampledIndices;
class="kw">private boolean warnedTruncation;
@Nullable
class="kw">private class="kw">final ActionList[] pool;
@Nullable
class="kw">private class="kw">final UUID[] slotUuid;
@Nullable
class="kw">private class="kw">final boolean[] slotSeen;
@Nullable
class="kw">private class="kw">final Object2IntMap<UUID> uuidToSlot;
class="kw">public ActionForEach(@Nonnull BuilderActionForEach var1, @Nonnull BuilderSupport var2) {
super(var1, var2);
this.maxTargets = var1.getMaxTargets(var2);
this.clearOncePerTarget = var1.isClearOncePerTarget(var2);
this.isolatePerTarget = var1.isIsolatePerTarget(var2);
int[] var3 = var1.getTargetCountRange(var2);
this.minTargetCount = var3[0];
this.maxTargetCount = var3[1];
if (this.maxTargetCount > 0) {
if (this.minTargetCount < 1) {
throw new IllegalStateException(
"ForEach TargetCount " + Arrays.toString(var3) + " must be a positive [min,max] with min <= max (or [-1,-1] to run every target)"
);
}
if (this.maxTargetCount > this.maxTargets) {
throw new IllegalStateException("ForEach TargetCount max (" + this.maxTargetCount + ") must not exceed MaxTargets (" + this.maxTargets + ")");
}
}
this.sampledIndices = this.maxTargetCount > 0 ? new int[this.maxTargetCount] : null;
if (this.isolatePerTarget) {
this.pool = new ActionList[this.maxTargets];
this.slotUuid = new UUID[this.maxTargets];
this.slotSeen = new boolean[this.maxTargets];
this.uuidToSlot = new Object2IntOpenHashMap(this.maxTargets);
this.uuidToSlot.defaultReturnValue(-1);
for (int var4 = 0; var4 < this.maxTargets; var4++) {
this.pool[var4] = var1.getActionList(var2);
}
} else {
this.pool = null;
this.slotUuid = null;
this.slotSeen = null;
this.uuidToSlot = null;
}
}
@Override
class="kw">public boolean canExecute(
@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nullable InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6
) {
if (this.once && this.triggered) {
class="kw">return false;
}
IPositionProvider var7 = var3 != null ? var3.getPositionProvider() : null;
class="kw">return var7 class="kw">instanceof IPositionSet var8 ? var8.size() > 0 : var7 != null && var7.hasPosition();
}
@Override
class="kw">public boolean execute(
@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nullable InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6
) {
this.triggered = true;
IPositionProvider var7 = var3 != null ? var3.getPositionProvider() : null;
if (var7 == null) {
class="kw">return true;
}
if (this.isolatePerTarget) {
assert this.slotSeen != null;
Arrays.fill(this.slotSeen, false);
}
if (var7 class="kw">instanceof IPositionSet var8) {
if (this.sampledIndices != null) {
int var9 = RandomExtra.randomRange(this.minTargetCount, this.maxTargetCount);
int var10 = RandomExtra.reservoirSample(var8.size(), var9, this.sampledIndices);
for (int var11 = 0; var11 < var10; var11++) {
this.runForElement(var1, var2, var8, this.sampledIndices[var11], var4, var6);
}
} else {
int var12 = Math.min(var8.size(), this.maxTargets);
if (var8.size() > this.maxTargets && !this.warnedTruncation) {
this.warnedTruncation = true;
LOGGER.at(Level.WARNING)
.log(
"ForEach capped at MaxTargets=%s but the sensor produced %s targets. %s skipped.",
this.maxTargets,
var8.size(),
var8.size() - this.maxTargets
);
}
for (int var13 = 0; var13 < var12; var13++) {
this.runForElement(var1, var2, var8, var13, var4, var6);
}
}
} else if (var7.hasPosition()) {
this.runShared(var1, var2, var3, var4, var6);
}
if (this.isolatePerTarget) {
this.releaseUnusedSlots();
}
class="kw">return true;
}
class="kw">private void runForElement(
@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull IPositionSet var3, int var4, double var5, @Nonnull Store<EntityStore> var7
) {
Ref var8 = var3.getTarget(var4);
if (var3.getPosition(var4, this.scratch)) {
this.perScoped.setTarget(this.scratch);
this.perScoped.setEntity(var8);
if (var3.getOrientation(var4, this.scratchRot)) {
this.perScoped.setOrientation(this.scratchRot);
} else {
this.perScoped.clearOrientation();
}
if (this.isolatePerTarget && var8 != null) {
UUIDComponent var9 = var7.getComponent(var8, UUIDComponent.getComponentType());
if (var9 != null) {
this.runIsolated(var1, var2, this.perScoped, var9.getUuid(), var5, var7);
class="kw">return;
}
}
this.runShared(var1, var2, this.perScoped, var5, var7);
}
}
class="kw">private void runShared(
@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nullable InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6
) {
if (this.clearOncePerTarget) {
this.actions.clearOnce();
}
this.actions.execute(var1, var2, var3, var4, var6);
}
class="kw">private void runIsolated(
@Nonnull Ref<EntityStore> var1,
@Nonnull ExecutionSupport var2,
@Nonnull InfoProvider var3,
@Nonnull UUID var4,
double var5,
@Nonnull Store<EntityStore> var7
) {
assert this.pool != null && this.slotUuid != null && this.slotSeen != null && this.uuidToSlot != null;
int var8 = this.uuidToSlot.getInt(var4);
if (var8 < 0) {
var8 = this.claimFreeSlot();
if (var8 < 0) {
class="kw">return;
}
this.uuidToSlot.put(var4, var8);
this.slotUuid[var8] = var4;
this.pool[var8].clearOnce();
}
this.slotSeen[var8] = true;
this.pool[var8].execute(var1, var2, var3, var5, var7);
}
class="kw">private int claimFreeSlot() {
assert this.pool != null && this.slotUuid != null;
for (int var1 = 0; var1 < this.pool.length; var1++) {
if (this.slotUuid[var1] == null) {
class="kw">return var1;
}
}
class="kw">return -1;
}
class="kw">private void releaseUnusedSlots() {
assert this.pool != null && this.slotUuid != null && this.slotSeen != null && this.uuidToSlot != null;
for (int var1 = 0; var1 < this.pool.length; var1++) {
if (this.slotUuid[var1] != null && !this.slotSeen[var1] && !this.pool[var1].isBusy()) {
this.uuidToSlot.removeInt(this.slotUuid[var1]);
this.slotUuid[var1] = null;
}
}
}
@Override
class="kw">public boolean isBusy() {
if (super.isBusy()) {
class="kw">return true;
}
if (this.pool != null) {
for (ActionList var4 : this.pool) {
if (var4.isBusy()) {
class="kw">return true;
}
}
}
class="kw">return false;
}
@Override
class="kw">public void registerWithSupport(ExecutionSupport var1) {
super.registerWithSupport(var1);
if (this.pool != null) {
for (ActionList var5 : this.pool) {
var5.registerWithSupport(var1);
}
}
}
@Override
class="kw">public void motionControllerChanged(
@Nullable Ref<EntityStore> var1, @Nonnull NPCEntity var2, MotionController var3, @Nullable ComponentAccessor<EntityStore> var4
) {
super.motionControllerChanged(var1, var2, var3, var4);
if (this.pool != null) {
for (ActionList var8 : this.pool) {
var8.motionControllerChanged(var1, var2, var3, var4);
}
}
}
@Override
class="kw">public void loaded(ExecutionSupport var1) {
super.loaded(var1);
if (this.pool != null) {
for (ActionList var5 : this.pool) {
var5.loaded(var1);
}
}
}
@Override
class="kw">public void spawned(ExecutionSupport var1) {
super.spawned(var1);
if (this.pool != null) {
for (ActionList var5 : this.pool) {
var5.spawned(var1);
}
}
}
@Override
class="kw">public void unloaded(ExecutionSupport var1) {
super.unloaded(var1);
if (this.pool != null) {
for (ActionList var5 : this.pool) {
var5.unloaded(var1);
}
}
}
@Override
class="kw">public void removed(ExecutionSupport var1) {
super.removed(var1);
if (this.pool != null) {
for (ActionList var5 : this.pool) {
var5.removed(var1);
}
}
}
@Override
class="kw">public void teleported(ExecutionSupport var1, World var2, World var3) {
super.teleported(var1, var2, var3);
if (this.pool != null) {
for (ActionList var7 : this.pool) {
var7.teleported(var1, var2, var3);
}
}
}
@Override
class="kw">public void clearOnce() {
super.clearOnce();
if (this.pool != null) {
for (ActionList var4 : this.pool) {
var4.clearOnce();
}
}
}
@Override
class="kw">public void setContext(IAnnotatedComponent var1, int var2) {
super.setContext(var1, var2);
if (this.pool != null) {
for (ActionList var6 : this.pool) {
var6.setContext(var1);
}
}
}
}