public function enableExpetiments(DataPacketSendEvent $event):void{
foreach($event->getPackets() as $packet) {
if (!$packet instanceof StartGamePacket) continue;
$experiments = $packet->levelSettings->experiments;
$ref_plop = new \ReflectionProperty($experiments, "experiments");
$ref_plop->setAccessible(true);
$ref_plop->setValue($experiments, array_merge($ref_plop->getValue($experiments), ['holiday_creator_features' => true]));
}...
なるほど、UseItemTransactionDataまでは見ていたのですがReleaseItemは弓だけだと思って見てませんでしたFoodやShooterのコンポーネントを持つアイテムは、
空中で使用されたときと、離されたときに二回クライアントサイドからInventoryTransactionPacketが送信されます。
そのパケットの中身にあるtrDataプロパティに、
使用が開始された際はUseItemTransactionDataが、
離された際にはReleaseItemTransactionDataが格納されているので、
サーバー側ではUseItemTransactionDataが格納されたInventoryTransactionPacketを感知してから、
ReleasseItemTransactionDataを格納したInventoryTransactionPacketを感知するまでの間がアイテムが右クリックされていると考えることができます。
しかし、一部のブロックやエンティティに対してアイテムが使用されたとき、
ReleaseItemTransactionDataが保証されない場合があるので、別途対策が必要です。
public function enableExpetiments(DataPacketSendEvent $event):void{
foreach($event->getPackets() as $packet) {
if (!$packet instanceof StartGamePacket) continue;
$experiments = $packet->levelSettings->experiments;
$ref_plop = new \ReflectionProperty($experiments, "experiments");
$ref_plop->setAccessible(true);
$ref_plop->setValue($experiments, array_merge($ref_plop->getValue($experiments), ['holiday_creator_features' => true]));
}
}
$parent_on_use = CompoundTag::create();{
$child_on_use = CompoundTag::create();{
$child_on_use->setString("event", "");
$child_on_use->setString("target", "self");
$parent_on_use->setTag("on_use", $child_on_use);
}
$components->setTag("minecraft:on_use", $parent_on_use);
}