Skip to content

Block Interactions

Interacciones específicas para bloques en el mundo.

Interacciones con Bloques

DestroyBlockInteraction

Destruye el bloque objetivo.

DestroyBlockInteraction destroy = new DestroyBlockInteraction();

// Uso en contexto
BlockPosition target = ctx.getTargetBlock();
if (target != null) {
    BlockHarvestUtils.performBlockBreak(
        entityRef,
        itemStack,
        position,
        chunkRef,
        commandBuffer,
        store
    );
}

PlaceBlockInteraction

Coloca un bloque en el mundo.

PlaceBlockInteraction place = new PlaceBlockInteraction();
place.blockType = "minecraft:stone";

ChangeBlockInteraction

Modifica un bloque existente (ej: cambiar estado).

ChangeBlockInteraction change = new ChangeBlockInteraction();
// Cambiar estado del bloque

Obtener Bloque Objetivo

// En InteractionContext
BlockPosition targetBlock = ctx.getMetaObject(Interaction.TARGET_BLOCK);
BlockPosition rawBlock = ctx.getMetaObject(Interaction.TARGET_BLOCK_RAW);

if (targetBlock != null) {
    int x = targetBlock.x;
    int y = targetBlock.y;
    int z = targetBlock.z;
    // Procesar bloque
}

Ejemplo Completo

public class MiInteraccionBloque extends SimpleInstantInteraction {
    @Override
    protected void firstRun(InteractionType type,
                           InteractionContext ctx,
                           CooldownHandler cooldown) {
        // Obtener bloque objetivo
        BlockPosition block = ctx.getTargetBlock();
        if (block == null) return;

        // Obtener mundo
        CommandBuffer<EntityStore> buffer = ctx.getCommandBuffer();
        World world = buffer.getExternalData().getWorld();

        // Obtener tipo de bloque
        ChunkStore chunks = world.getChunkStore();
        int blockType = chunks.getBlockType(block.x, block.y, block.z);

        // Procesar según tipo
        if (blockType == BlockTypes.STONE) {
            // Lógica para piedra
        }

        // Completar interacción
        ctx.getState().state = InteractionState.Finished;
    }
}

Ver También