SpawnDeployableFromRaycastInteraction class
Пакет: com.hypixel.hytale.builtin.deployables.interaction
Файл: com/hypixel/hytale/builtin/deployables/interaction/SpawnDeployableFromRaycastInteraction.java
extends: SimpleInstantInteraction
Поля (18)
| Модификаторы | Тип | Имя |
|---|---|---|
|
Vector3d |
var10 |
|
Rotation3f |
var11 |
|
float |
var12 |
|
Rotation3f |
var13 |
|
float |
var14 |
|
Vector3d |
var15 |
|
com.hypixel.hytale.protocol.SpawnDeployableFromRaycastInteraction |
var2 |
|
EntityStatMap |
var3 |
|
CommandBuffer |
var4 |
|
ObjectIterator |
var4 |
|
InteractionSyncData |
var5 |
|
Entry |
var5 |
|
Ref |
var6 |
|
EntityStatValue |
var6 |
|
Store |
var7 |
|
Position |
var8 |
|
|
var8 |
|
TransformComponent |
var9 |
Методы (8)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
protected |
boolean |
canAffordboolean canAfford(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) |
|
|
if if(this.unknownEntityStats != null) |
|
|
if if(var6 != null) |
|
|
if if(var8 == null) |
|
|
if if(var5.raycastNormal != null) |
|
|
if if(var3 == null) |
static |
boolean |
isSurfaceboolean isSurface(@Nonnull Rotation3f var0) |
private |
void |
processConfigvoid processConfig() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.deployables.interaction;
class="kw">import com.hypixel.hytale.builtin.deployables.DeployablesUtils;
class="kw">import com.hypixel.hytale.builtin.deployables.config.DeployableConfig;
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.map.Object2FloatMapCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
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.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.protocol.Interaction;
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.Position;
class="kw">import com.hypixel.hytale.protocol.WaitForDataFrom;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entitystats.EntityStatMap;
class="kw">import com.hypixel.hytale.server.core.modules.entitystats.EntityStatValue;
class="kw">import com.hypixel.hytale.server.core.modules.entitystats.EntityStatsModule;
class="kw">import com.hypixel.hytale.server.core.modules.entitystats.asset.EntityStatType;
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.universe.world.storage.EntityStore;
class="kw">import it.unimi.dsi.fastutil.ints.Int2FloatMap;
class="kw">import it.unimi.dsi.fastutil.ints.Int2FloatMap.Entry;
class="kw">import it.unimi.dsi.fastutil.objects.Object2FloatMap;
class="kw">import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectIterator;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">public class SpawnDeployableFromRaycastInteraction class="kw">extends SimpleInstantInteraction {
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<SpawnDeployableFromRaycastInteraction> CODEC = BuilderCodec.builder(
SpawnDeployableFromRaycastInteraction.class, SpawnDeployableFromRaycastInteraction::new, SimpleInstantInteraction.CODEC
)
.append(new KeyedCodec<>("Config", DeployableConfig.CODEC), (var0, var1) -> var0.config = var1, var0 -> var0.config)
.addValidator(Validators.nonNull())
.add()
.<Object2FloatMap<String>>append(
new KeyedCodec<>("PreviewStatConditions", new Object2FloatMapCodec<>(Codec.STRING, Object2FloatOpenHashMap::new)),
(var0, var1) -> var0.unknownEntityStats = var1,
var0 -> var0.unknownEntityStats
)
.addValidator(EntityStatType.VALIDATOR_CACHE.getMapKeyValidator())
.documentation("Modifiers to apply to EntityStats.")
.add()
.<Float>appendInherited(
new KeyedCodec<>("MaxPlacementDistance", Codec.FLOAT),
(var0, var1) -> var0.maxPlacementDistance = var1,
var0 -> var0.maxPlacementDistance,
(var0, var1) -> var0.maxPlacementDistance = var1.maxPlacementDistance
)
.documentation("The max distance at which the player can deploy the deployable.")
.add()
.afterDecode(SpawnDeployableFromRaycastInteraction::processConfig)
.build();
class="kw">protected Object2FloatMap<String> unknownEntityStats;
@Nullable
class="kw">protected Int2FloatMap entityStats;
class="kw">protected float maxPlacementDistance;
class="kw">private DeployableConfig config;
class="kw">public SpawnDeployableFromRaycastInteraction() {
}
class="kw">private void processConfig() {
if (this.unknownEntityStats != null) {
this.entityStats = EntityStatsModule.resolveEntityStats(this.unknownEntityStats);
}
}
class="kw">private class="kw">static boolean isSurface(@Nonnull Rotation3f var0) {
class="kw">return var0.x == 0.0F && Math.abs(var0.y - 1.0F) < 0.01 && var0.z == 0.0F;
}
@Override
class="kw">public boolean needsRemoteSync() {
class="kw">return true;
}
@Nonnull
@Override
class="kw">public WaitForDataFrom getWaitForDataFrom() {
class="kw">return WaitForDataFrom.Client;
}
@Override
class="kw">protected void firstRun(@Nonnull InteractionType var1, @Nonnull InteractionContext var2, @Nonnull CooldownHandler var3) {
CommandBuffer var4 = var2.getCommandBuffer();
assert var4 != null;
if (!this.canAfford(var2.getEntity(), var4)) {
var2.getState().state = InteractionState.Failed;
} else {
InteractionSyncData var5 = var2.getClientState();
assert var5 != null;
Ref var6 = var2.getOwningEntity();
if (var6 != null) {
Store var7 = var4.getStore();
Position var8 = var5.raycastHit;
if (var8 == null) {
TransformComponent var9 = var7.getComponent(var6, TransformComponent.getComponentType());
assert var9 != null;
Vector3d var10 = var9.getPosition();
var8 = new Position((float)var10.x, (float)var10.y, (float)var10.z);
}
if (var5.raycastNormal != null) {
float var14 = var5.raycastDistance;
Vector3d var15 = new Vector3d(var8.x, var8.y, var8.z);
Rotation3f var11 = new Rotation3f(var5.raycastNormal.x(), var5.raycastNormal.y(), var5.raycastNormal.z());
if (var14 > 0.0F && var14 <= this.maxPlacementDistance && (this.config.getAllowPlaceOnWalls() || isSurface(var11))) {
float var12 = var5.attackerRot != null ? var5.attackerRot.yaw : 0.0F;
Rotation3f var13 = new Rotation3f(0.0F, var12, 0.0F);
DeployablesUtils.spawnDeployable(var4, var7, this.config, var6, var15, var13, "UP");
}
}
}
}
}
class="kw">protected boolean canAfford(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
if (this.entityStats != null && !this.entityStats.isEmpty()) {
EntityStatMap var3 = var2.getComponent(var1, EntityStatMap.getComponentType());
if (var3 == null) {
class="kw">return false;
}
ObjectIterator var4 = this.entityStats.int2FloatEntrySet().iterator();
while (var4.hasNext()) {
Entry var5 = (Entry)var4.next();
EntityStatValue var6 = var3.get(var5.getIntKey());
if (var6 == null || var6.get() < var5.getFloatValue()) {
class="kw">return false;
}
}
class="kw">return true;
} else {
class="kw">return true;
}
}
@Nonnull
@Override
class="kw">protected Interaction generatePacket() {
class="kw">return new com.hypixel.hytale.protocol.SpawnDeployableFromRaycastInteraction();
}
@Override
class="kw">protected void configurePacket(Interaction var1) {
super.configurePacket(var1);
com.hypixel.hytale.protocol.SpawnDeployableFromRaycastInteraction var2 = (com.hypixel.hytale.protocol.SpawnDeployableFromRaycastInteraction)var1;
var2.deployableConfig = this.config.toPacket();
var2.maxDistance = this.maxPlacementDistance;
var2.costs = this.entityStats;
}
}