2017-11-17 58 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);