A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

[Sponge]インベントリを扱う

インベントリの中を参照する

ClickInventoryEventでevent.getTargetInventory().slots()で参照できますので、先ずはその内容から。
※注意:この内容で作業台をクリックするとエラーになります。

@Listener
public void onEvent( ClickInventoryEvent event ){
 int i = 0;
 for ( Inventory slot:event.getTargetInventory().slots() ){
  if (slot.peek().isPresent()){
   ItemStack itema = slot.peek().get();
   this.ginou.info( i + ": " + itema.getItem().getId() );
  }else{
   this.ginou.info( i + ": null" );
  }
  i++;
 }
}

slot.peek()ですが、peek(のぞき見る)で参照できます。slot.poll()でもほぼ同じ事ができますが、pollを実行するとそのスロットは空になるので注意。slot.set(<ItemStack>)で格納もできます。

取得したデータは以下の通りのようです

No, 中身
0~8 ホットバー(最下段)の内容。0が一番左
9~35 インベントリ(3行×9列)の中身。9が一番左上。10がその右隣。35が一番右下。
36 頭の装備
37 胴の装備
38 レギンスの装備
39 ブーツの装備
40~43 クラフトエリア。40:左上、41:右上、42:左下、43右下
44~47 何故か40~43と同じ。
48 クラフトでの完成後
49 オフハンド

ちなみにチェストを開くと以下の通りになりました。開く内容によって状態が変わるようですね。

No, 中身
0~26 チェストの中身(3行×9列)
27~53 インベントリの中身(3行×9列)
54~62 ホットバーの中身

とりあえず、event.getTargetInventory().slots()としましたが、player.getTargetInventory().slots()もできますが、これは常に「プレイヤーのインベントリ」が表示されます。
微妙にClickInventoryEventの時のevent.getTargetInventory().slots()の順番と装備の部分が違うのと、何故かレギンスが二箇所でます。また、オフハンドも見れないみたいですね。

No, 中身
0~8 ホットバー(最下段)の内容。0が一番左
9~35 インベントリ(3行×9列)の中身。9が一番左上。10がその右隣。35が一番右下。
36 ブーツの装備
37 レギンスの装備
38 胴の装備
39 頭の装備
40 レギンスの装備

 

まだ不明な箇所がいくつかありますが、そのうち必要なら書くかもです。

コメントを残す

これらのHTMLタグが利用可能です

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Time limit is exhausted. Please reload CAPTCHA.

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.