SpawnDeployableFromRaycastInteraction.java
package com.hypixel.hytale.builtin.deployables.interaction;
import com.hypixel.hytale.builtin.deployables.DeployablesUtils;
import com.hypixel.hytale.builtin.deployables.config.DeployableConfig;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.codec.codecs.map.Object2FloatMapCodec;
import com.hypixel.hytale.codec.validation.Validators;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.math.vector.Vector3f;
import com.hypixel.hytale.protocol.Direction;
import com.hypixel.hytale.protocol.Interaction;
import com.hypixel.hytale.protocol.InteractionState;
import com.hypixel.hytale.protocol.InteractionSyncData;
import com.hypixel.hytale.protocol.InteractionType;
import com.hypixel.hytale.protocol.Position;
import com.hypixel.hytale.protocol.WaitForDataFrom;
import com.hypixel.hytale.server.core.entity.InteractionContext;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.modules.entitystats.EntityStatMap;
import com.hypixel.hytale.server.core.modules.entitystats.EntityStatValue;
import com.hypixel.hytale.server.core.modules.entitystats.EntityStatsModule;
com.hypixel.hytale.server.core.modules.entitystats.asset.EntityStatType;
com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
com.hypixel.hytale.server.core.modules.interaction.interaction.config.SimpleInstantInteraction;
com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
it.unimi.dsi.fastutil.ints.Int2FloatMap;
it.unimi.dsi.fastutil.objects.Object2FloatMap;
it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
javax.annotation.Nonnull;
{
BuilderCodec<SpawnDeployableFromRaycastInteraction> CODEC;
Object2FloatMap<String> unknownEntityStats;
Int2FloatMap entityStats;
maxPlacementDistance;
DeployableConfig config;
{
}
{
(.unknownEntityStats != ) {
.entityStats = EntityStatsModule.resolveEntityStats(.unknownEntityStats);
}
}
{
normal.x == && ()(normal.y - ) < && normal.z == ;
}
{
;
}
WaitForDataFrom {
WaitForDataFrom.Client;
}
{
Ref<EntityStore> entityRef = context.getOwningEntity();
Store<EntityStore> store = entityRef.getStore();
CommandBuffer<EntityStore> commandBuffer = context.getCommandBuffer();
commandBuffer != ;
context.getClientState();
clientState != ;
(!.canAfford(context.getEntity(), commandBuffer)) {
context.getState().state = InteractionState.Failed;
} {
clientState.raycastHit;
(raycastHit == ) {
(TransformComponent)store.getComponent(entityRef, TransformComponent.getComponentType());
transformComponent != ;
transformComponent.getPosition();
raycastHit = (()(()position.x), ()(()position.y), ()(()position.z));
}
com.hypixel.hytale.protocol. clientState.raycastNormal;
clientState.raycastDistance;
com.hypixel.hytale.protocol. .hypixel.hytale.protocol.Vector3f(()raycastHit.x, ()raycastHit.y, ()raycastHit.z);
(raycastNormal.x, raycastNormal.y, raycastNormal.z);
(correctedRaycastDistance > && correctedRaycastDistance <= .maxPlacementDistance && (.config.getAllowPlaceOnWalls() || isSurface(norm))) {
clientState.attackerRot;
(, attackerRot.yaw, );
DeployablesUtils.spawnDeployable(commandBuffer, store, .config, entityRef, (spawnPosition.x, spawnPosition.y, spawnPosition.z), rot, );
}
}
}
{
(.entityStats != && !.entityStats.isEmpty()) {
(EntityStatMap)componentAccessor.getComponent(entityRef, EntityStatMap.getComponentType());
(entityStatMapComponent == ) {
;
} {
(Int2FloatMap.Entry cost : .entityStats.int2FloatEntrySet()) {
entityStatMapComponent.get(cost.getIntKey());
(stat == || stat.get() < cost.getFloatValue()) {
;
}
}
;
}
} {
;
}
}
Interaction {
.hypixel.hytale.protocol.SpawnDeployableFromRaycastInteraction();
}
{
.configurePacket(packet);
com.hypixel.hytale.protocol. (com.hypixel.hytale.protocol.SpawnDeployableFromRaycastInteraction)packet;
p.deployableConfig = .config.toPacket();
p.maxDistance = .maxPlacementDistance;
p.costs = .entityStats;
}
{
CODEC = ((BuilderCodec.Builder)((BuilderCodec.Builder)((BuilderCodec.Builder)((BuilderCodec.Builder)BuilderCodec.builder(SpawnDeployableFromRaycastInteraction.class, SpawnDeployableFromRaycastInteraction::, SimpleInstantInteraction.CODEC).append( (, DeployableConfig.CODEC), (i, s) -> i.config = s, (i) -> i.config).addValidator(Validators.nonNull()).add()).append( (, (Codec.STRING, Object2FloatOpenHashMap::)), (changeStatInteraction, stringObject2DoubleMap) -> changeStatInteraction.unknownEntityStats = stringObject2DoubleMap, (changeStatInteraction) -> changeStatInteraction.unknownEntityStats).addValidator(EntityStatType.VALIDATOR_CACHE.getMapKeyValidator()).documentation().add()).appendInherited( (, Codec.FLOAT), (o, i) -> o.maxPlacementDistance = i, (o) -> o.maxPlacementDistance, (i, o) -> i.maxPlacementDistance = o.maxPlacementDistance).documentation().add()).afterDecode(SpawnDeployableFromRaycastInteraction::processConfig)).build();
}
}