Gametest(scriptingAPI)制作メモ – world.event

GameTest

このページは緑茶がGametestで制作時に使用した物を置いています。備忘録みたいな物です。
バージョンアップにより使えなくなった物、間違えている箇所がある可能性があります

import

import { DynamicPropertiesDefinition, MinecraftEntityTypes, system, world } from “@minecraft/server”;

基本:worldのみ

system:scriptEventReceiveを使う時に必要

DynamicPropertiesDefinition,
MinecraftEntityTypes:
1.20.30にて削除されました

ダイナミックプロパティを使う時に必要

ワールドロード時 : world.afterEvents.worldInitialize

world.afterEvents.worldInitialize.subscribe(ev => {
});

用途

ダイナミックプロパティの設定

プレイヤースポーン時 : world.afterEvents.playerSpawn

world.afterEvents.playerSpawn.subscribe(ev =>{
});

プレイヤーの取得

 const player = ev.player;

参加時のみ動くコード

if(ev.initialSpawn){
player.runCommand(`say 初めのスポーン`);
}

用途

プレイヤー死亡検知
ログイン時初期化

■ 広告 ■

アイテム右クリック(1回) : world.afterEvents.itemUse

world.afterEvents.itemUse.subscribe((event) => {
});

プレイヤーとアイテムの取得

const { source, itemStack } = event;

アイテム別に処理を行う

if (itemStack.typeId == ‘test:aaa’)return;
if (itemStack.typeId == ‘test:aaa’)return;

switch(itemStack.typeId)
{
case “minecraft:diamond;break;
case “minecraft:emerald;break;
}

用途

右クリック検知
疑似食べ物(特定の条件下でカスタムアイテムを食べた時に発生する(していた)クラッシュ対策)

scripteventコマンド : system.afterEvents.scriptEventReceive

system.afterEvents.scriptEventReceive.subscribe(ev =>{
});

実行者とオプションの取得

const { id, sourceEntity,message } = ev;

id別に処理を分ける

 if(id == “test:aaa”)return;
if(id == “test:bbb”)return;

オプションを使う

sourceEntity.runCommand(`say ${message}`);

用途

scripteventコマンドの使用

■ 広告 ■

攻撃(無敵時間無視) : world.afterEvents.entityHitEntity

world.afterEvents.entityHitEntity.subscribe(ev => {
});

攻撃したエンティティと受けたエンティティの取得

const { damagingEntity:attacker, hitEntity:entity } = ev;

受けたエンティティからコマンド実行

entity.runCommand(`say ${attacker.typeId}`);

用途

無敵時間を無視した攻撃判定

攻撃(無敵時間考慮) : world.afterEvents.entityHurt

world.afterEvents.entityHurt.subscribe(ev => {
});

攻撃したエンティティと受けたエンティティ、ダメージの取得

const { hurtEntity, damageSource,damage:number } = ev;
const attacker = damageSource.damagingEntity;

用途

攻撃時にスクリプト処理

チャットを送った時 : world.beforeEvents.chatSend

world.beforeEvents.chatSend.subscribe(ev => {
});

チャットを送った内容とプレイヤーの取得

let { sender, message } = ev;

チャットの送信をキャンセル

 ev.cancel = true;

beforeEventsになってからチャットを何かしらするには遅延をかける必要がある

投擲物に当たった時 : world.afterEvents.projectileHitEntity

world.afterEvents.projectileHitEntity.subscribe((eventData) => {
});

射撃したエンティティ、当たったエンティティ、投げられた物の取得

const { projectile,source } = eventData;
const hitEntity = eventData.getEntityHit().entity;

用途

・銃アドオンの作成、弓矢の拡張

投擲物がブロックに当たった時 : world.afterEvents.projectileHitBlock

world.afterEvents.projectileHitBlock.subscribe((eventData) => {
});

用途

・銃アドオンの作成、弓矢の拡張

コメント