ProjectileInteraction class
Пакет: com.hypixel.hytale.server.core.modules.projectile.interaction
Файл: com/hypixel/hytale/server/core/modules/projectile/interaction/ProjectileInteraction.java
extends: SimpleInstantInteraction
implements: BallisticDataProvider
Поля (25)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
HytaleLogger |
LOGGER |
|
Transform |
var10 |
|
Rotation3f |
var11 |
|
InteractionChain |
var12 |
|
InteractionEntry |
var13 |
|
Long |
var14 |
|
com.hypixel.hytale.protocol.ProjectileInteraction |
var2 |
|
ProjectileConfig |
var3 |
|
Transform |
var3 |
|
ProjectileConfig |
var4 |
|
CommandBuffer |
var4 |
|
double |
var4 |
|
Ref |
var5 |
|
Ref |
var5 |
|
Ref |
var6 |
|
Transform |
var6 |
|
Velocity |
var6 |
|
CommandBuffer |
var7 |
|
InteractionSyncData |
var7 |
|
double |
var7 |
|
InteractionSyncData |
var8 |
|
Rotation3f |
var8 |
|
UUID |
var9 |
|
|
var9 |
|
double |
var9 |
Методы (9)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
return new |
Transformreturn new Transform(var1.attackerPos.x, var1.attackerPos.y, var1.attackerPos.z, var1.attackerRot.pitch, var1.attackerRot.yaw, var1.attackerRot.roll) |
|
|
if if(var4 != null) |
|
|
if if(var8 != null && var8.generatedUUID != null) |
|
|
if if(this.ignorePitch) |
|
|
if if(this.ignoreYaw) |
|
|
if if(this.ignoreRoll) |
|
|
if if(var3 == null) |
|
|
if if(var1 != null && var1.attackerPos != null && var1.attackerRot != null) |
|
|
if if(var4 > var9 * 1.25) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.projectile.interaction;
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.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.util.HashUtil;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.math.vector.Transform;
class="kw">import com.hypixel.hytale.protocol.Direction;
class="kw">import com.hypixel.hytale.protocol.Interaction;
class="kw">import com.hypixel.hytale.protocol.InteractionSyncData;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.protocol.WaitForDataFrom;
class="kw">import com.hypixel.hytale.server.core.entity.EntityUtils;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionChain;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionEntry;
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.physics.component.Velocity;
class="kw">import com.hypixel.hytale.server.core.modules.projectile.ProjectileModule;
class="kw">import com.hypixel.hytale.server.core.modules.projectile.config.BallisticData;
class="kw">import com.hypixel.hytale.server.core.modules.projectile.config.BallisticDataProvider;
class="kw">import com.hypixel.hytale.server.core.modules.projectile.config.ProjectileConfig;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.core.util.PositionUtil;
class="kw">import com.hypixel.hytale.server.core.util.TargetUtil;
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">public class ProjectileInteraction class="kw">extends SimpleInstantInteraction class="kw">implements BallisticDataProvider {
class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
class="kw">private class="kw">static class="kw">final double SPAWN_TRANSFORM_DESYNC_ALLOWANCE_MULTIPLIER = 1.25;
class="kw">private class="kw">static class="kw">final double SPAWN_TRANSFORM_DESYNC_ALLOWANCE_MINIMUM_SQUARED = 0.5;
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<ProjectileInteraction> CODEC = BuilderCodec.builder(
ProjectileInteraction.class, ProjectileInteraction::new, SimpleInstantInteraction.CODEC
)
.documentation("Fires a projectile.")
.<String>appendInherited(
new KeyedCodec<>("Config", Codec.STRING), (var0, var1) -> var0.config = var1, var0 -> var0.config, (var0, var1) -> var0.config = var1.config
)
.addValidator(ProjectileConfig.VALIDATOR_CACHE.getValidator().late())
.documentation("The ID of the projectile config asset to use for the projectile.")
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("IgnorePitch", Codec.BOOLEAN),
(var0, var1) -> var0.ignorePitch = var1,
var0 -> var0.ignorePitch,
(var0, var1) -> var0.ignorePitch = var1.ignorePitch
)
.documentation(
"If true, the shooter's pitch is set to 0 before the launch direction is computed, so the projectile's pitch is fixed by the projectile config's SpawnRotationOffset."
)
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("IgnoreYaw", Codec.BOOLEAN),
(var0, var1) -> var0.ignoreYaw = var1,
var0 -> var0.ignoreYaw,
(var0, var1) -> var0.ignoreYaw = var1.ignoreYaw
)
.documentation(
"If true, the shooter's yaw is set to 0 before the launch direction is computed, so the projectile's yaw is fixed by the projectile config's SpawnRotationOffset."
)
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("IgnoreRoll", Codec.BOOLEAN),
(var0, var1) -> var0.ignoreRoll = var1,
var0 -> var0.ignoreRoll,
(var0, var1) -> var0.ignoreRoll = var1.ignoreRoll
)
.documentation(
"If true, the shooter's roll is set to 0 before the launch direction is computed, so the projectile's roll is fixed by the projectile config's SpawnRotationOffset."
)
.add()
.build();
class="kw">protected String config;
class="kw">protected boolean ignorePitch;
class="kw">protected boolean ignoreYaw;
class="kw">protected boolean ignoreRoll;
class="kw">public ProjectileInteraction() {
}
@Nullable
class="kw">public ProjectileConfig getConfig() {
class="kw">return ProjectileConfig.getAssetMap().getAsset(this.config);
}
@Nullable
@Override
class="kw">public BallisticData getBallisticData() {
class="kw">return this.getConfig();
}
@Nonnull
@Override
class="kw">public WaitForDataFrom getWaitForDataFrom() {
class="kw">return WaitForDataFrom.Client;
}
@Override
class="kw">public boolean needsRemoteSync() {
class="kw">return true;
}
@Override
class="kw">protected void firstRun(@Nonnull InteractionType var1, @Nonnull InteractionContext var2, @Nonnull CooldownHandler var3) {
ProjectileConfig var4 = this.getConfig();
if (var4 != null) {
Ref var5 = var2.getOwningEntity();
Ref var6 = var5 != null && var5.isValid() ? var5 : var2.getEntity();
CommandBuffer var7 = var2.getCommandBuffer();
assert var7 != null;
InteractionSyncData var8 = var2.getClientState();
UUID var9 = null;
if (var8 != null && var8.generatedUUID != null) {
var9 = var8.generatedUUID;
}
Transform var10 = this.getProjectileSpawnSource(var8, var2);
Rotation3f var11 = var10.getRotation();
if (this.ignorePitch) {
var11.setPitch(0.0F);
}
if (this.ignoreYaw) {
var11.setYaw(0.0F);
}
if (this.ignoreRoll) {
var11.setRoll(0.0F);
}
InteractionChain var12 = var2.getChain();
InteractionEntry var13 = var2.getEntry();
Long var14 = var12 != null && var13 != null ? HashUtil.hash(var12.getChainId(), var13.getIndex()) : null;
ProjectileModule.get().spawnProjectile(var9, var14, var6, var7, var4, var10.getPosition(), var10.getDirection());
}
}
@Override
class="kw">protected void simulateFirstRun(@Nonnull InteractionType var1, @Nonnull InteractionContext var2, @Nonnull CooldownHandler var3) {
CommandBuffer var4 = var2.getCommandBuffer();
assert var4 != null;
Ref var5 = var2.getEntity();
Transform var6 = TargetUtil.getLook(var5, var4);
InteractionSyncData var7 = var2.getState();
var7.attackerPos = PositionUtil.toPositionPacket(var6.getPosition());
Rotation3f var8 = var6.getRotation();
var7.attackerRot = new Direction(var8.yaw(), var8.pitch(), var8.roll());
}
@Nonnull
@Override
class="kw">protected Interaction generatePacket() {
class="kw">return new com.hypixel.hytale.protocol.ProjectileInteraction();
}
@Override
class="kw">protected void configurePacket(Interaction var1) {
super.configurePacket(var1);
com.hypixel.hytale.protocol.ProjectileInteraction var2 = (com.hypixel.hytale.protocol.ProjectileInteraction)var1;
ProjectileConfig var3 = this.getConfig();
if (var3 == null) {
throw new IllegalStateException("ProjectileInteraction '" + this.getId() + "' has no valid ProjectileConfig: " + this.config);
}
var2.configId = this.config;
var2.ignorePitch = this.ignorePitch;
var2.ignoreYaw = this.ignoreYaw;
var2.ignoreRoll = this.ignoreRoll;
}
@Nonnull
class="kw">private Transform getProjectileSpawnSource(@Nullable InteractionSyncData var1, @Nonnull InteractionContext var2) {
Transform var3 = TargetUtil.getLook(var2.getEntity(), var2.getCommandBuffer());
if (var1 != null && var1.attackerPos != null && var1.attackerRot != null) {
double var4 = var3.getPosition().distanceSquared(var1.attackerPos.x, var1.attackerPos.y, var1.attackerPos.z);
Velocity var6 = var2.getCommandBuffer().getComponent(var2.getEntity(), Velocity.getComponentType());
double var7 = var6 != null ? var6.getClientVelocity().lengthSquared() : 0.0;
double var9 = Math.max(var7, 0.5);
if (var4 > var9 * 1.25) {
LOGGER.at(Level.WARNING)
.log(
"%s was too far from requested projectile spawn position (%f > %f)",
EntityUtils.getEntityName(var2.getEntity(), var2.getCommandBuffer()),
var4,
var9
);
class="kw">return var3;
} else {
class="kw">return new Transform(
var1.attackerPos.x, var1.attackerPos.y, var1.attackerPos.z, var1.attackerRot.pitch, var1.attackerRot.yaw, var1.attackerRot.roll
);
}
} else {
class="kw">return var3;
}
}
}