エンティティ
- ブロックに対して自ら移動しうる物体のこと。
(playerやモンスターや生物のこと) - 絵画や額縁など移動しないが内部ではエンティティとして扱われているもの。
- 投射物
(矢や火の玉)
実装
@EventHandler
public void onPlayerToggleSneak(PlayerToggleSneakEvent e) throws IOException {
これの上に追加
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
}
pllayerが、Join(ゲームに参加したとき、ワールドに入ったとき)
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
Player player = e.getPlayer();
World world = player.getWorld();
}
playerとworldを取ってくる
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
Player player = e.getPlayer();
World world = player.getWorld();
Location playerlocation = player.getLocation();
}
そして、ロケーションを取ってくる。
playerの今いる位置を取ってくるということ
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
Player player = e.getPlayer();
World world = player.getWorld();
Location playerlocation = player.getLocation();
world.spawnEntity()
}
発生させるという指示を追加
new Location(座標を弄りたいときの指示)
world.spawnEntity(new Location(world, 0,0,0));
(world, 0,0,0) = 引数にworldの情報(どのworldに発生させるのか)がいり、x軸,y軸,z軸を指定
EntityType.CHICKEN)
エンティティのタイプは、ドットを入力すると用意してある。
そしたら
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
Player player = e.getPlayer();
World world = player.getWorld();
Location playerlocation = player.getLocation();
world.spawnEntity(new Location(world, 0,0,0), EntityType.CHICKEN);
}
Chicken chicken = world.spawn(new Location(world, 0,0,0), Chicken.class);
に変更。
classを指定するとそのクラスのエンティティが返ってくる。
class自体が明確ならば、コードしてきれいだしオブジェクトとして扱いやすい。
ここは、用途によって書き方がある。
しかし、これでは、どこに現れるかわからないので、
world.spawn(new Location(world, playerlocation.getX() + 3, playerlocation.getY(), playerlocation.getZ()), Chicken.class);
に変更。
ここでは、chickenに対しては、何もしないので変数を取らないで良いため「Chicken chicken =」は、削除。
しか〜し!!
ここで、エラー波線が出たままになっている。
このままでは、動かない予感がしたので、エラー内容を見てみると
すでに、「onPlayerJoin」はありますとの表示!!
以前、ワールドに入ったら表示させるという指示を残したままになっていたので、そこをコメントアウトすると・・・
エラーが消えました!!
まずは、なにも出現しないことを確認し

プログラムを実行し、コマンドで「reload」を行う。

成功!!!
ちなみに、ロバを出現させてみました。

成功!!!
コメント