2017-11-17 108 views
1

我是新來的插件開發BukkitBukkit/JavaPlugin - 設置結果爲現有的各具特色的食譜不工作

對於我的私人服務器的Minecraft我想添加/修改各具特色的食譜。我想手藝SlimeBlocks只有4個SlimeBalls所以這裏是我得到:

@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方法/是什麼控制檯說? – MCMastery

+0

只需簡單的看一下,'Bukket.getServer()。recipeIterator()'可能是隻讀的。 – MCMastery

+0

@MCMastery no no錯誤沒有警告,如果我記錄結果的emount它顯示正確的值,但在Minecraft中沒有任何變化。我不認爲它的只讀,因爲然後setAmount會拋出和錯誤/警告?! – KilledByCheese

回答

1

我通過改變一些東西得到它的工作s ... Shapedrecipe只給出配方的克隆/副本,而不是實際的配方。 我用PrepareItemCraftEvent如果一個球員想要的東西手藝改變結果:

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); 
    } 

} 
} 

在我註冊了我的監聽 getServer().getPluginManager().registerEvents(new MyListener(), this);

相關問題