Interaction System
The Interaction System manages how players and entities interact with the game world through mouse clicks, block interactions, and entity interactions.
Core Components
Section titled “Core Components”InteractionModule
Section titled “InteractionModule”The main module class that registers interaction types and manages the interaction system.
Location: com.hypixel.hytale.server.core.modules.interaction.InteractionModule
// Get the module instanceInteractionModule module = InteractionModule.get();
// Get component typesComponentType<EntityStore, InteractionManager> managerType = module.getInteractionManagerComponent();ComponentType<EntityStore, Interactions> interactionsType = module.getInteractionsComponentType();Interactions Component
Section titled “Interactions Component”Stores the mapping of interaction types to root interaction IDs for an entity.
Location: com.hypixel.hytale.server.core.modules.interaction.Interactions
// Get interaction ID for a specific typeInteractions component = store.getComponent(entityRef, Interactions.getComponentType());String interactionId = component.getInteractionId(InteractionType.Primary);
// Set interaction IDcomponent.setInteractionId(InteractionType.Primary, "hytale:basic_attack");Interaction Types:
Primary- Left clickSecondary- Right clickTertiary- Middle clickAbility1-4- Ability slotsProjectileImpact- Projectile hitProjectileSpawn- After projectile spawned- And more…
InteractionManager Component
Section titled “InteractionManager Component”Manages active interaction chains and cooldowns for an entity. This is automatically added to entities by the PlayerAddManagerSystem.
Location: com.hypixel.hytale.server.core.entity.InteractionManager
Root Interactions
Section titled “Root Interactions”Root interactions are entry points that define what happens when a specific interaction type is triggered.
RootInteraction
Section titled “RootInteraction”Location: com.hypixel.hytale.server.core.modules.interaction.interaction.config.RootInteraction
Asset Path: Item/RootInteractions/{id}.json
{ "Interactions": ["hytale:damage_entity", "hytale:play_sound"], "Cooldown": { "Id": "attack_cooldown", "Cooldown": 0.5, "Charges": [0.5, 1.0] }, "Rules": { "BlockingRoots": ["hytale:mining"], "AllowedGameModes": ["Adventure", "Survival"] }}Key Fields:
Interactions- Array of interaction IDs to execute in sequenceCooldown- Optional cooldown configurationRules- Restrictions on when this interaction can runSettings- Per-gamemode settings
Cooldowns
Section titled “Cooldowns”Cooldowns prevent interactions from running too frequently.
Location: com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler
// Check if on cooldownCooldownHandler handler = /* get from manager */;boolean onCooldown = handler.isOnCooldown( rootInteraction, "my_cooldown_id", maxTime, chargeTimes, interruptRecharge);
// Reset cooldownhandler.resetCooldown("my_cooldown_id", maxTime, chargeTimes, interruptRecharge);Charge System:
- Cooldowns can have multiple charges
- Each charge has a recharge time
- Using an action consumes one charge
InterruptRechargedetermines if using resets the recharge timer
Interaction Chains
Section titled “Interaction Chains”Interactions can be chained together to create complex behaviors.
Interaction Types
Section titled “Interaction Types”All interactions extend the base Interaction class.
Location: com.hypixel.hytale.server.core.modules.interaction.interaction.config.Interaction
Common Interaction Types:
Client-Side Interactions
Section titled “Client-Side Interactions”Executed on client with server validation:
PlaceBlock- Place a block in the worldBreakBlock- Break a blockUseBlock- Interact with a block (doors, chests)UseEntity- Interact with an entityCharging- Hold to charge (bow drawing)Chaining- Chain multiple clicksChangeBlock- Modify block typeChangeState- Modify block stateFirstClick- Only runs on first clickApplyForce- Apply physics force
Server-Side Interactions
Section titled “Server-Side Interactions”Executed only on server:
DamageEntity- Damage an entity with selectorsLaunchProjectile- Spawn a projectileSpawnPrefab- Spawn an entityApplyEffect- Apply entity effectClearEntityEffect- Remove entity effectChangeStat- Modify entity statsOpenContainer- Open inventory UIOpenPage- Open custom UIEquipItem- Equip armor/itemsModifyInventory- Add/remove itemsSendMessage- Send chat messageDoor- Open/close doorsLaunchPad- Launch entity with velocity
Control Flow Interactions
Section titled “Control Flow Interactions”Control execution flow:
Condition- Conditional executionSerial- Run interactions in sequenceParallel- Run interactions simultaneouslyRepeat- Repeat interactionsSelect- Choose based on selectorReplace- Replace with different interactionCancelChain- Stop chain executionInterrupt- Interrupt active chains
Condition Interactions
Section titled “Condition Interactions”BlockCondition- Check block type/stateCooldownCondition- Check cooldown stateEffectCondition- Check entity effectsStatsCondition- Check entity statsMovementCondition- Check movement stateDestroyCondition- Check if can destroyPlacementCountCondition- Check placed block count
Selectors
Section titled “Selectors”Selectors determine which entities are targeted by interactions.
Location: com.hypixel.hytale.server.core.modules.interaction.interaction.config.selector.SelectorType
Selector Types:
Raycast- Ray cast from entity look directionHorizontal- Horizontal arc around entityStab- Forward stab hitboxAOECircle- Circle area around pointAOECylinder- Cylinder area around entity
{ "Type": "Selector", "Selector": { "Type": "AOECircle", "Radius": 5.0, "Angle": 90.0 }, "EntityMatchers": ["Vulnerable"], "Interactions": ["hytale:damage_entity"]}Entity Matchers:
Vulnerable- Can be damagedPlayer- Players only
Block Interactions
Section titled “Block Interactions”Special utilities for block-related interactions.
BlockInteractionUtils
Section titled “BlockInteractionUtils”Location: com.hypixel.hytale.server.core.modules.interaction.BlockInteractionUtils
Handles block interaction logic like determining if a block can be interacted with.
BlockPlaceUtils
Section titled “BlockPlaceUtils”Location: com.hypixel.hytale.server.core.modules.interaction.BlockPlaceUtils
Utilities for validating and executing block placement.
BlockHarvestUtils
Section titled “BlockHarvestUtils”Location: com.hypixel.hytale.server.core.modules.interaction.BlockHarvestUtils
Handles block breaking and loot drops.
PlacedByInteractionComponent
Section titled “PlacedByInteractionComponent”Tracks which player placed a block, useful for tracking structures.
Location: com.hypixel.hytale.server.core.modules.interaction.components.PlacedByInteractionComponent
ComponentType<ChunkStore, PlacedByInteractionComponent> type = InteractionModule.get().getPlacedByComponentType();
PlacedByInteractionComponent component = chunkStore.getComponent(blockRef, type);if (component != null) { UUID placerUUID = component.getPlacedBy(); // Use placer UUID}Interaction Effects
Section titled “Interaction Effects”Effects that play during interactions (particles, sounds, animations).
Location: com.hypixel.hytale.server.core.modules.interaction.interaction.config.InteractionEffects
{ "Effects": { "Particles": ["hytale:sparkle"], "Sounds": ["hytale:whoosh"], "Animation": "hytale:swing", "Trail": "hytale:sword_slash", "ModelOverlay": "hytale:glow" }}Interaction Context
Section titled “Interaction Context”Provides context information when executing interactions.
Location: com.hypixel.hytale.server.core.entity.InteractionContext
// Create context for entityInteractionContext context = InteractionContext.forEntity( interactionManager, livingEntity, InteractionType.Primary);
// Create context for proxy entity (projectiles)InteractionContext proxyContext = InteractionContext.forProxyEntity( interactionManager, creatorEntity, projectileRef);
// Access context dataRef<EntityStore> entity = context.getEntity();CommandBuffer<EntityStore> buffer = context.getCommandBuffer();String rootInteractionId = context.getRootInteractionId(InteractionType.Primary);Systems
Section titled “Systems”The interaction module registers several ECS systems:
PlayerAddManagerSystem
Section titled “PlayerAddManagerSystem”Automatically adds InteractionManager component to entities when needed.
TickInteractionManagerSystem
Section titled “TickInteractionManagerSystem”Updates active interaction chains each tick.
CleanUpSystem
Section titled “CleanUpSystem”Removes completed interaction data.
TrackerTickSystem
Section titled “TrackerTickSystem”Updates interaction tracking for networked entities.
Example: Custom Interaction
Section titled “Example: Custom Interaction”// Create a custom damage interactionpublic class CustomDamageInteraction extends Interaction { @Override protected void firstRun( InteractionType type, InteractionContext context, CooldownHandler cooldownHandler ) { // Get target from context Ref<EntityStore> target = context.getTarget(); if (target == null) return;
// Create damage CommandBuffer<EntityStore> buffer = context.getCommandBuffer(); Damage damage = new Damage(10.0f); damage.setSource(context.getEntity());
// Apply damage buffer.invoke(target, damage); }}Example: Running an Interaction Chain
Section titled “Example: Running an Interaction Chain”// Get componentsInteractionManager manager = store.getComponent( playerRef, InteractionModule.get().getInteractionManagerComponent());Player player = EntityUtils.getEntity(playerRef, store);
// Get root interactionRootInteraction root = RootInteraction.getRootInteractionOrUnknown( "hytale:attack");
// Create contextInteractionContext context = InteractionContext.forEntity( manager, (LivingEntity) player, InteractionType.Primary);
// Initialize and execute chainInteractionChain chain = manager.initChain( InteractionType.Primary, context, root, true // sendToClient);manager.queueExecuteChain(chain);Block Tracking
Section titled “Block Tracking”Track player-placed blocks for limits or statistics.
BlockCounter
Section titled “BlockCounter”Location: com.hypixel.hytale.server.core.modules.interaction.blocktrack.BlockCounter
Resource that counts blocks placed by category.
TrackedPlacement
Section titled “TrackedPlacement”Location: com.hypixel.hytale.server.core.modules.interaction.blocktrack.TrackedPlacement
Component that tracks placement data for a specific block.
// Get resource typeResourceType<ChunkStore, BlockCounter> counterType = InteractionModule.get().getBlockCounterResourceType();
// Get component typeComponentType<ChunkStore, TrackedPlacement> placementType = InteractionModule.get().getTrackedPlacementComponentType();