1.16.5 How to use bone meal to around crops with ProtocolLib

Discussion in 'Spigot Plugin Development' started by Zemelua, Jun 26, 2021.

  1. プレイヤーがこっそりと忍び寄るとき、私は周囲の植物に骨粉を与えようとしています。スニーク中に周囲の植物を手に入れることができましたが、骨粉を与えるためにどのパケットを使用するかわかりません。誰か知っている?

    [コード] @EventHandler
    public void onPlayerToggleSneak(PlayerToggleSneakEvent event){
    if(event.isSneaking()){
    this.getAroundPlants(event.getPlayer()、3、2);
    }
    }

    private void getAroundPlants(Player player、int vRange、int hRange){
    ロケーションセンター= player.getLocation();
    for(int x = -vRange; x <= vRange; x ++){
    for(int y = -hRange; y <= hRange; y ++){
    for(int z = -vRange; z <= vRange; z ++){
    ブロックブロック= player.getWorld()。getBlockAt(x + center.getBlockX()、y + center.getBlockY()、z + center.getBlockZ());
    BlockData blockData = block.getBlockData();

    if(blockData instanceof Sapling){
    this.sendGrowPacket(block、player);
    } else if(blockData instanceof Ageable){
    Ageable ageableData =(Ageable)blockData;
    if(ageableData.getAge()<ageableData.getMaximumAge()){
    this.sendGrowPacket(block、player);
    }
    }
    }
    }
    }
    }

    private void sendGrowPacket(Block block、Player player){
    ProtocolManager protocolManager = this.bumperDance.getProtocolManager();
    PacketContainerコンテナ= protocolManager.createPacket(//?);

    // どうやって?

    {を試してください
    protocolManager.recieveClientPacket(player、container);
    } catch(InvocationTargetException | IllegalAccessException例外){
    exception.printStackTrace();
    }
    }[/コード]
     
  2. I see, the growth of crops is quite so with block.setBlockData, but how can I grow saplings?
     
  3. Saplings don't grow into Trees......

    Code (Java):
    public static boolean growSapling(Block block) {
       BlockData blockData = block.getBlockData().clone();
       if (!(blockData instanceof Sapling)) return false;

       block.getWorld().playEffect(block.getLocation(), Effect.VILLAGER_PLANT_GROW, Integer.valueOf(0));

       Sapling saplingData = (Sapling) blockData;
       int currentStage = saplingData.getStage();
       if (currentStage >= saplingData.getMaximumStage()) return false;

       saplingData.setStage(currentStage + 1);
       block.setBlockData(saplingData);

       return true;
    }