2017-11-17 2 views
1

を働いていない既存のクラフトレシピの結果を設定します。私は私が得たものであるので、ここでわずか4 SlimeBallsでSlimeBlocksを作るにしたい:Bukkit/JavaPlugin - 私はレシピを作り上げる/変更を追加したい私のプライベートのMinecraft Serverの場合Bukkit</p> <p>のために、私はプラグイン開発に新たなんだ

@Override 
public void onEnable() { 

    ItemStack slimeBlockStack = new ItemStack(Material.SLIME_BLOCK); 
    ShapedRecipe slimeBlockRecipe = new ShapedRecipe(slimeBlockStack); 

    slimeBlockRecipe.shape("###", "#oo", "#oo"); 
    slimeBlockRecipe.setIngredient('o', Material.SLIME_BALL); 
    slimeBlockRecipe.setIngredient('#', Material.AIR); 

    getServer().addRecipe(slimeBlockRecipe); 

//....here comes more 
} 

今、あなたは4でブロックを作り上げ、その後戻って、私は結果を上書きしたい9 slimeballsにそれを作り上げることでslimeballsを「ごまかす」ことができないので、既存のクラフトレシピの - 私は、すべてのレシピのリストを反復処理しようとし、結果の量を設定し、それが動作していない...私は間違って

Iterator<Recipe> it = Bukkit.getServer().recipeIterator(); 
    while(it.hasNext()) { 
     ItemStack result = it.next().getResult(); 
     if(result.isSimilar(new ItemStack(Material.SLIME_BALL))) { 

      result.setAmount(4); 

     } 
    } 

何をやっている、私はすべての助けをapreciate /ヒント

+0

すべてのエラー/コンソールが何を言ってん私のリスナーを登録しonEnable方法で

public class MyListener implements Listener { @EventHandler public void craftEvent(PrepareItemCraftEvent event) { ItemStack[] contents = event.getInventory().getContents(); ItemStack firstInContents = contents[0]; if((firstInContents.getType()==Material.SLIME_BALL) && (firstInContents.getAmount() == 9)) { firstInContents.setAmount(4); } } } 

MCMastery

+0

クイックルックで、 'Bukket.getServer()。recipeIterator()'はおそらく読み取り専用です。 – MCMastery

+0

@MCMastery noエラーはありません警告、結果のemountを記録すると正しい値が表示されますが、Minecraftでは何も変わりません。私は、そのsetAmountがスローされ、エラー/警告があるため、その読み込みのみとは思っていませんか? – KilledByCheese

答えて

1

何かを変えて作業しています... Shapedrecipeは、実際のレシピではなくレシピのクローン/コピーを提供します。 私はプレイヤーが何かを作るしたい場合は、結果を変更するためにPrepareItemCraftEventを使用:?私は getServer().getPluginManager().registerEvents(new MyListener(), this);

関連する問題