ApplyForceInteraction class
Пакет: com.hypixel.hytale.server.core.modules.interaction.interaction.config.client
Файл: com/hypixel/hytale/server/core/modules/interaction/interaction/config/client/ApplyForceInteraction.java
extends: SimpleInteraction
Поля (39)
| Модификаторы | Тип | Имя |
|---|---|---|
|
public static final BuilderCodec<ApplyForceInteraction.Force> |
CODEC |
|
private boolean |
adjustVertical |
|
|
break |
|
|
break |
|
|
break |
|
|
break |
|
private final Vector3d |
direction |
|
private double |
force |
|
HeadRotation |
var10 |
|
Velocity |
var11 |
|
Rotation3f |
var12 |
|
ChangeVelocityType |
var13 |
|
|
var13 |
|
Vector3d |
var18 |
|
float |
var19 |
|
|
var19 |
|
Label[] |
var2 |
|
com.hypixel.hytale.protocol.ApplyForceInteraction |
var2 |
|
boolean |
var20 |
|
boolean |
var21 |
|
MovementStatesComponent |
var22 |
|
TransformComponent |
var23 |
|
MovementStates |
var24 |
|
SpatialResource |
var25 |
|
SpatialStructure |
var26 |
|
List |
var27 |
|
boolean |
var28 |
|
boolean |
var29 |
|
boolean |
var30 |
|
boolean |
var31 |
|
Label |
var4 |
|
Interaction |
var4 |
|
InteractionSyncData |
var6 |
|
InteractionSyncData |
var6 |
|
InteractionSyncData |
var7 |
|
Ref |
var7 |
|
ApplyForceState |
var8 |
|
CommandBuffer |
var8 |
|
Store |
var9 |
Методы (16)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
public |
Forcepublic Force() |
|
|
for for(ApplyForceInteraction.Force var17 : this.forces) |
|
|
for for(int var3 = 0; var3 < var2.length; var3++) |
|
|
if if(var1) |
|
|
if if(var29) |
|
|
if if(var17.adjustVertical) |
|
|
if if(this.verticalClamp != null) |
|
|
if if(var1 != null) |
|
|
if if(this.verticalClamp != null) |
static |
void |
resolvevoid resolve(@Nonnull OperationsBuilder var0, @Nullable String var1, @Nonnull Label var2, @Nonnull Label var3) |
abstract |
|
resolve resolve(var1, this.next, var2[0], var4) |
abstract |
|
resolve resolve(var1, this.groundInteraction == null ? this.next : this.groundInteraction, var2[1], var4) |
abstract |
|
resolve resolve(var1, this.collisionInteraction == null ? this.next : this.collisionInteraction, var2[2], var4) |
|
|
switch switch(var8) |
|
|
switch switch(var13) |
|
public AppliedForce |
toPacketpublic AppliedForce toPacket() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.interaction.interaction.config.client;
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.codecs.EnumCodec;
class="kw">import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
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.component.Store;
class="kw">import com.hypixel.hytale.component.spatial.SpatialResource;
class="kw">import com.hypixel.hytale.component.spatial.SpatialStructure;
class="kw">import com.hypixel.hytale.math.range.FloatRange;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.math.vector.Vector3dUtil;
class="kw">import com.hypixel.hytale.protocol.AppliedForce;
class="kw">import com.hypixel.hytale.protocol.ApplyForceState;
class="kw">import com.hypixel.hytale.protocol.ChangeVelocityType;
class="kw">import com.hypixel.hytale.protocol.InteractionState;
class="kw">import com.hypixel.hytale.protocol.InteractionSyncData;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.protocol.MovementStates;
class="kw">import com.hypixel.hytale.protocol.RaycastMode;
class="kw">import com.hypixel.hytale.protocol.WaitForDataFrom;
class="kw">import com.hypixel.hytale.server.core.codec.ProtocolCodecs;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.entity.movement.MovementStatesComponent;
class="kw">import com.hypixel.hytale.server.core.io.NetworkSerializable;
class="kw">import com.hypixel.hytale.server.core.modules.entity.EntityModule;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.Interaction;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.SimpleInteraction;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.operation.Label;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.operation.OperationsBuilder;
class="kw">import com.hypixel.hytale.server.core.modules.physics.component.Velocity;
class="kw">import com.hypixel.hytale.server.core.modules.splitvelocity.VelocityConfig;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.Arrays;
class="kw">import java.util.List;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">import org.joml.Vector3f;
class="kw">public class ApplyForceInteraction class="kw">extends SimpleInteraction {
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<ApplyForceInteraction> CODEC = BuilderCodec.builder(
ApplyForceInteraction.class, ApplyForceInteraction::new, SimpleInteraction.CODEC
)
.documentation("Applies a force to the user, optionally waiting for a condition to met before continuing.")
.<Vector3d>appendInherited(
new KeyedCodec<>("Direction", Vector3dUtil.CODEC), (var0, var1) -> var0.forces[0].direction.set(var1.normalize()), var0 -> null, (var0, var1) -> {}
)
.documentation("The direction of the force to apply.")
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("AdjustVertical", Codec.BOOLEAN), (var0, var1) -> var0.forces[0].adjustVertical = var1, var0 -> null, (var0, var1) -> {}
)
.documentation("Whether the force should be adjusted based on the vertical look of the user.")
.add()
.<Double>appendInherited(new KeyedCodec<>("Force", Codec.DOUBLE), (var0, var1) -> var0.forces[0].force = var1, var0 -> null, (var0, var1) -> {})
.documentation("The size of the force to apply.")
.add()
.<ApplyForceInteraction.Force[]>appendInherited(
new KeyedCodec<>("Forces", new ArrayCodec<>(ApplyForceInteraction.Force.CODEC, ApplyForceInteraction.Force[]::new)),
(var0, var1) -> var0.forces = var1,
var0 -> var0.forces,
(var0, var1) -> var0.forces = var1.forces
)
.addValidator(Validators.nonNull())
.documentation("A collection of forces to apply to the user.\nReplaces `Direction`, `AdjustVertical` and `Force` if used.")
.add()
.<Float>appendInherited(
new KeyedCodec<>("Duration", Codec.FLOAT), (var0, var1) -> var0.duration = var1, var0 -> var0.duration, (var0, var1) -> var0.duration = var1.duration
)
.addValidator(Validators.greaterThanOrEqual(0.0F))
.documentation("The duration for which force should be continuously applied. If 0, force is applied on first run.")
.add()
.<FloatRange>appendInherited(
new KeyedCodec<>("VerticalClamp", FloatRange.CODEC),
(var0, var1) -> var0.verticalClamp = var1,
var0 -> var0.verticalClamp,
(var0, var1) -> var0.verticalClamp = var1.verticalClamp
)
.documentation("The angles in degrees to clamp the look angle to when adjusting the force")
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("WaitForGround", Codec.BOOLEAN),
(var0, var1) -> var0.waitForGround = var1,
var0 -> var0.waitForGround,
(var0, var1) -> var0.waitForGround = var1.waitForGround
)
.documentation("Determines whether or not on ground should be checked")
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("WaitForCollision", Codec.BOOLEAN),
(var0, var1) -> var0.waitForCollision = var1,
var0 -> var0.waitForCollision,
(var0, var1) -> var0.waitForCollision = var1.waitForCollision
)
.documentation("Determines whether or not collision should be checked")
.add()
.<Float>appendInherited(
new KeyedCodec<>("RaycastDistance", Codec.FLOAT),
(var0, var1) -> var0.raycastDistance = var1,
var0 -> var0.raycastDistance,
(var0, var1) -> var0.raycastDistance = var1.raycastDistance
)
.documentation("The distance of the raycast for the collision check")
.add()
.<Float>appendInherited(
new KeyedCodec<>("RaycastHeightOffset", Codec.FLOAT),
(var0, var1) -> var0.raycastHeightOffset = var1,
var0 -> var0.raycastHeightOffset,
(var0, var1) -> var0.raycastHeightOffset = var1.raycastHeightOffset
)
.documentation("The height offset of the raycast for the collision check (class="kw">default 0)")
.add()
.<RaycastMode>appendInherited(
new KeyedCodec<>("RaycastMode", new EnumCodec<>(RaycastMode.class)),
(var0, var1) -> var0.raycastMode = var1,
var0 -> var0.raycastMode,
(var0, var1) -> var0.raycastMode = var1.raycastMode
)
.documentation("The type of raycast performed for the collision check")
.add()
.<Float>appendInherited(
new KeyedCodec<>("GroundCheckDelay", Codec.FLOAT),
(var0, var1) -> var0.groundCheckDelay = var1,
var0 -> var0.groundCheckDelay,
(var0, var1) -> var0.groundCheckDelay = var1.groundCheckDelay
)
.documentation("The delay in seconds before checking if on ground")
.add()
.<Float>appendInherited(
new KeyedCodec<>("CollisionCheckDelay", Codec.FLOAT),
(var0, var1) -> var0.collisionCheckDelay = var1,
var0 -> var0.collisionCheckDelay,
(var0, var1) -> var0.collisionCheckDelay = var1.collisionCheckDelay
)
.documentation("The delay in seconds before checking entity collision")
.add()
.<ChangeVelocityType>appendInherited(
new KeyedCodec<>("ChangeVelocityType", ProtocolCodecs.CHANGE_VELOCITY_TYPE_CODEC),
(var0, var1) -> var0.changeVelocityType = var1,
var0 -> var0.changeVelocityType,
(var0, var1) -> var0.changeVelocityType = var1.changeVelocityType
)
.documentation("Configures how the velocity gets applied to the user.")
.add()
.<VelocityConfig>appendInherited(
new KeyedCodec<>("VelocityConfig", VelocityConfig.CODEC),
(var0, var1) -> var0.velocityConfig = var1,
var0 -> var0.velocityConfig,
(var0, var1) -> var0.velocityConfig = var1.velocityConfig
)
.documentation("Specific configuration options that control how the velocity is affected.")
.add()
.<String>appendInherited(
new KeyedCodec<>("GroundNext", Interaction.CHILD_ASSET_CODEC),
(var0, var1) -> var0.groundInteraction = var1,
var0 -> var0.groundInteraction,
(var0, var1) -> var0.groundInteraction = var1.groundInteraction
)
.documentation("The interaction to run if on-ground is apparent.")
.addValidatorLate(() -> VALIDATOR_CACHE.getValidator().late())
.add()
.<String>appendInherited(
new KeyedCodec<>("CollisionNext", Interaction.CHILD_ASSET_CODEC),
(var0, var1) -> var0.collisionInteraction = var1,
var0 -> var0.collisionInteraction,
(var0, var1) -> var0.collisionInteraction = var1.collisionInteraction
)
.documentation("The interaction to run if collision is apparent.")
.addValidatorLate(() -> VALIDATOR_CACHE.getValidator().late())
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("UseTargetBlockForDirection", Codec.BOOLEAN),
(var0, var1) -> var0.useTargetBlockForDirection = var1,
var0 -> var0.useTargetBlockForDirection,
(var0, var1) -> var0.useTargetBlockForDirection = var1.useTargetBlockForDirection
)
.documentation(
"Determines whether to align the direction to the target block of the interaction chain.\nThe interaction ignores `Direction` and `Forces` if this is used, only the settings in the root \nof the interaction will be used."
)
.add()
.build();
class="kw">private class="kw">static class="kw">final int LABEL_COUNT = 3;
class="kw">private class="kw">static class="kw">final int NEXT_LABEL_INDEX = 0;
class="kw">private class="kw">static class="kw">final int GROUND_LABEL_INDEX = 1;
class="kw">private class="kw">static class="kw">final int COLLISION_LABEL_INDEX = 2;
class="kw">private class="kw">static class="kw">final float SPATIAL_STRUCTURE_RADIUS = 1.5F;
@Nonnull
class="kw">private ChangeVelocityType changeVelocityType = ChangeVelocityType.Set;
@Nonnull
class="kw">private ApplyForceInteraction.Force[] forces = new ApplyForceInteraction.Force[]{new ApplyForceInteraction.Force()};
class="kw">private float duration = 0.0F;
class="kw">private boolean waitForGround = true;
class="kw">private boolean waitForCollision = false;
class="kw">private float groundCheckDelay = 0.1F;
class="kw">private float collisionCheckDelay = 0.0F;
class="kw">private float raycastDistance = 1.5F;
class="kw">private float raycastHeightOffset = 0.0F;
@Nonnull
class="kw">private RaycastMode raycastMode = RaycastMode.FollowMotion;
@Nullable
class="kw">private VelocityConfig velocityConfig = null;
@Nullable
class="kw">private FloatRange verticalClamp = null;
@Nullable
class="kw">private String groundInteraction = null;
@Nullable
class="kw">private String collisionInteraction = null;
class="kw">private boolean useTargetBlockForDirection;
class="kw">public ApplyForceInteraction() {
}
@Nonnull
@Override
class="kw">public WaitForDataFrom getWaitForDataFrom() {
class="kw">return WaitForDataFrom.Client;
}
@Override
class="kw">protected void tick0(boolean var1, float var2, @Nonnull InteractionType var3, @Nonnull InteractionContext var4, @Nonnull CooldownHandler var5) {
InteractionSyncData var6 = var4.getState();
if (var1) {
var6.state = InteractionState.NotFinished;
} else {
InteractionSyncData var7 = var4.getClientState();
assert var7 != null;
ApplyForceState var8 = var7.applyForceState;
class="kw">switch (var8) {
case Ground:
var6.state = InteractionState.Finished;
var4.jump(var4.getLabel(1));
break;
case Collision:
var6.state = InteractionState.Finished;
var4.jump(var4.getLabel(2));
break;
case Timer:
var6.state = InteractionState.Finished;
var4.jump(var4.getLabel(0));
break;
class="kw">default:
var6.state = InteractionState.NotFinished;
}
super.tick0(var1, var2, var3, var4, var5);
}
}
@Override
class="kw">protected void simulateTick0(boolean var1, float var2, @Nonnull InteractionType var3, @Nonnull InteractionContext var4, @Nonnull CooldownHandler var5) {
InteractionSyncData var6 = var4.getState();
Ref var7 = var4.getEntity();
CommandBuffer var8 = var4.getCommandBuffer();
assert var8 != null;
Store var9 = var8.getStore();
if (!var1 && (!(this.duration > 0.0F) || !(var2 < this.duration))) {
MovementStatesComponent var22 = var9.getComponent(var7, MovementStatesComponent.getComponentType());
assert var22 != null;
TransformComponent var23 = var9.getComponent(var7, TransformComponent.getComponentType());
assert var23 != null;
MovementStates var24 = var22.getMovementStates();
SpatialResource var25 = var9.getResource(EntityModule.get().getNetworkSendableSpatialResourceType());
SpatialStructure var26 = var25.getSpatialStructure();
List var27 = SpatialResource.getThreadLocalReferenceList();
var26.collect(var23.getPosition(), 1.5, var27);
boolean var28 = var2 >= this.groundCheckDelay;
boolean var29 = var28 && this.waitForGround && (var24.onGround || var24.inFluid || var24.climbing);
boolean var30 = var2 >= this.collisionCheckDelay;
boolean var31 = var30 && this.waitForCollision && var27.size() > 1;
boolean var20 = this.runTime <= 0.0F && !this.waitForGround && !this.waitForCollision;
boolean var21 = var20 || this.runTime > 0.0F && var2 >= this.runTime;
var6.applyForceState = ApplyForceState.Waiting;
if (var29) {
var6.applyForceState = ApplyForceState.Ground;
var6.state = InteractionState.Finished;
var4.jump(var4.getLabel(1));
} else if (var31) {
var6.applyForceState = ApplyForceState.Collision;
var6.state = InteractionState.Finished;
var4.jump(var4.getLabel(2));
} else if (var21) {
var6.applyForceState = ApplyForceState.Timer;
var6.state = InteractionState.Finished;
var4.jump(var4.getLabel(0));
} else {
var6.state = InteractionState.NotFinished;
}
super.simulateTick0(var1, var2, var3, var4, var5);
} else {
HeadRotation var10 = var9.getComponent(var7, HeadRotation.getComponentType());
assert var10 != null;
Velocity var11 = var9.getComponent(var7, Velocity.getComponentType());
assert var11 != null;
Rotation3f var12 = var10.getRotation();
ChangeVelocityType var13 = this.changeVelocityType;
for (ApplyForceInteraction.Force var17 : this.forces) {
Vector3d var18 = new Vector3d(var17.direction);
if (var17.adjustVertical) {
float var19 = var12.x;
if (this.verticalClamp != null) {
var19 = MathUtil.clamp(
var19, this.verticalClamp.getInclusiveMin() * (float) (Math.PI / 180.0), this.verticalClamp.getInclusiveMax() * (float) (Math.PI / 180.0)
);
}
var18.rotateX(var19);
}
var18.mul(var17.force);
var18.rotateY(var12.y);
class="kw">switch (var13) {
case Add:
var11.addInstruction(var18, null, ChangeVelocityType.Add);
break;
case Set:
var11.addInstruction(var18, null, ChangeVelocityType.Set);
}
var13 = ChangeVelocityType.Add;
}
var6.state = InteractionState.NotFinished;
}
}
@Override
class="kw">public void compile(@Nonnull OperationsBuilder var1) {
Label[] var2 = new Label[3];
for (int var3 = 0; var3 < var2.length; var3++) {
var2[var3] = var1.createUnresolvedLabel();
}
var1.addOperation(this, var2);
Label var4 = var1.createUnresolvedLabel();
resolve(var1, this.next, var2[0], var4);
resolve(var1, this.groundInteraction == null ? this.next : this.groundInteraction, var2[1], var4);
resolve(var1, this.collisionInteraction == null ? this.next : this.collisionInteraction, var2[2], var4);
var1.resolveLabel(var4);
}
class="kw">private class="kw">static void resolve(@Nonnull OperationsBuilder var0, @Nullable String var1, @Nonnull Label var2, @Nonnull Label var3) {
var0.resolveLabel(var2);
if (var1 != null) {
Interaction var4 = Interaction.getInteractionOrUnknown(var1);
var4.compile(var0);
}
var0.jump(var3);
}
@Override
class="kw">public boolean needsRemoteSync() {
class="kw">return true;
}
@Nonnull
@Override
class="kw">protected com.hypixel.hytale.protocol.Interaction generatePacket() {
class="kw">return new com.hypixel.hytale.protocol.ApplyForceInteraction();
}
@Override
class="kw">protected void configurePacket(com.hypixel.hytale.protocol.Interaction var1) {
super.configurePacket(var1);
com.hypixel.hytale.protocol.ApplyForceInteraction var2 = (com.hypixel.hytale.protocol.ApplyForceInteraction)var1;
var2.changeVelocityType = this.changeVelocityType;
var2.forces = Arrays.stream(this.forces).map(ApplyForceInteraction.Force::toPacket).toArray(AppliedForce[]::new);
var2.duration = this.duration;
var2.waitForGround = this.waitForGround;
var2.waitForCollision = this.waitForCollision;
var2.groundCheckDelay = this.groundCheckDelay;
var2.collisionCheckDelay = this.collisionCheckDelay;
var2.velocityConfig = this.velocityConfig == null ? null : this.velocityConfig.toPacket();
if (this.verticalClamp != null) {
var2.verticalClamp = new com.hypixel.hytale.protocol.FloatRange(
this.verticalClamp.getInclusiveMin() * (float) (Math.PI / 180.0), this.verticalClamp.getInclusiveMax() * (float) (Math.PI / 180.0)
);
}
var2.collisionNext = Interaction.getInteractionIdOrUnknown(this.collisionInteraction == null ? this.next : this.collisionInteraction);
var2.groundNext = Interaction.getInteractionIdOrUnknown(this.groundInteraction == null ? this.next : this.groundInteraction);
var2.raycastDistance = this.raycastDistance;
var2.raycastHeightOffset = this.raycastHeightOffset;
var2.raycastMode = this.raycastMode;
var2.useTargetBlockForDirection = this.useTargetBlockForDirection;
}
@Nonnull
@Override
class="kw">public String toString() {
class="kw">return "ApplyForceInteraction{changeVelocityType=" + this.changeVelocityType + ", waitForGround=" + this.waitForGround + "} " + super.toString();
}
class="kw">public class="kw">static class Force class="kw">implements NetworkSerializable<AppliedForce> {
class="kw">public class="kw">static class="kw">final BuilderCodec<ApplyForceInteraction.Force> CODEC = BuilderCodec.builder(
ApplyForceInteraction.Force.class, ApplyForceInteraction.Force::new
)
.appendInherited(
new KeyedCodec<>("Direction", Vector3dUtil.CODEC),
(var0, var1) -> var0.direction.set(var1),
var0 -> var0.direction,
(var0, var1) -> var0.direction.set(var1.direction)
)
.documentation("The direction of the force to apply.")
.addValidator(Validators.nonNull())
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("AdjustVertical", Codec.BOOLEAN),
(var0, var1) -> var0.adjustVertical = var1,
var0 -> var0.adjustVertical,
(var0, var1) -> var0.adjustVertical = var1.adjustVertical
)
.documentation("Whether the force should be adjusted based on the vertical look of the user.")
.add()
.<Double>appendInherited(
new KeyedCodec<>("Force", Codec.DOUBLE), (var0, var1) -> var0.force = var1, var0 -> var0.force, (var0, var1) -> var0.force = var1.force
)
.documentation("The size of the force to apply.")
.add()
.afterDecode(var0 -> var0.direction.normalize())
.build();
@Nonnull
class="kw">private class="kw">final Vector3d direction = new Vector3d(Vector3dUtil.UP);
class="kw">private boolean adjustVertical = false;
class="kw">private double force = 1.0;
class="kw">public Force() {
}
@Nonnull
class="kw">public AppliedForce toPacket() {
class="kw">return new AppliedForce(
new Vector3f((float)this.direction.x, (float)this.direction.y, (float)this.direction.z), this.adjustVertical, (float)this.force
);
}
}
}