Tutorial: Custom Interaction¶
Aprende a crear una interacción personalizada para items.
Objetivo¶
Crear una interacción que teletransporta al jugador cuando usa un item.
Paso 1: Crear Clase de Interacción¶
package com.ejemplo.interactions;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.protocol.InteractionState;
import com.hypixel.hytale.protocol.InteractionType;
import com.hypixel.hytale.server.core.entity.InteractionContext;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
import com.hypixel.hytale.server.core.modules.interaction.interaction.config.SimpleInstantInteraction;
public class TeleportInteraction extends SimpleInstantInteraction {
public TeleportInteraction() {
this.id = "mymod:teleport";
this.runTime = 1.0f; // 1 segundo de cooldown
}
@Override
protected void firstRun(InteractionType type,
InteractionContext context,
CooldownHandler cooldownHandler) {
// Obtener jugador
var entityRef = context.getEntity();
var buffer = context.getCommandBuffer();
var entity = buffer.getEntity(entityRef);
if (!(entity instanceof Player)) {
context.getState().state = InteractionState.Failed;
return;
}
Player player = (Player) entity;
// Teletransportar 10 bloques adelante
Vector3d pos = player.getPosition();
Vector3d dir = player.getLookDirection();
player.setPosition(new Vector3d(
pos.x + dir.x * 10,
pos.y,
pos.z + dir.z * 10
));
player.sendMessage("¡Teletransportado!");
context.getState().state = InteractionState.Finished;
}
}
Paso 2: Registrar Interacción¶
public class MyPlugin {
public static void registerInteractions() {
var store = Interaction.getAssetStore();
store.loadAssets("MyMod:MyMod", List.of(
new TeleportInteraction()
));
}
}
Paso 3: Cargar al Inicio¶
Usar un transformador para llamar el registro:
public class PluginTransformer implements ClassTransformer {
@Override
public byte[] transform(String className,
String classPath,
byte[] bytecode) {
if (className.equals("com.hypixel.hytale.server.core.HytaleServer")) {
// Inyectar llamada a MyPlugin.registerInteractions()
return injectRegistration(bytecode);
}
return null;
}
}
Paso 4: Usar en Item¶
En el JSON de configuración del item:
Siguiente¶
- Metadata Storage: Tutorial de metadatos
- Interaction System: Documentación completa