Bukkit/JavaPlugin-设置现有工艺配方的结果不起作用
我是Bukkit插件开发新手 对于我的私人Minecraft服务器,我想添加/更改工艺配方。我想用4个粘球制作粘锁,所以我得到的是:Bukkit/JavaPlugin-设置现有工艺配方的结果不起作用,java,minecraft,bukkit,Java,Minecraft,Bukkit,我是Bukkit插件开发新手 对于我的私人Minecraft服务器,我想添加/更改工艺配方。我想用4个粘球制作粘锁,所以我得到的是: @Override public void onEnable() { ItemStack slimeBlockStack = new ItemStack(Material.SLIME_BLOCK); ShapedRecipe slimeBlockRecipe = new ShapedRecipe(slimeBlockStack); s
@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个泥球来“欺骗”泥球。我想覆盖现有制作配方的结果-我试图迭代所有配方的列表,然后设置结果的数量,但它不起作用
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);
}
}
Iterator it=Bukkit.getServer().recipeIterator();
while(it.hasNext()){
ItemStack result=it.next().getResult();
if(结果相似(新项目堆栈(材料粘球))){
结果:setAmount(4);
}
}
我做错了什么,我感谢每一个帮助/提示我通过改变一些东西使它工作起来。。。 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);
}
}
}
在onEnable方法中,我注册了我的侦听器
getServer()代码>任何错误/控制台怎么说?快速查看,Bukket.getServer().recipeIterator()可能是只读的。@MCMastery没有错误没有警告,如果我记录结果的emount,它会显示正确的值,但在Minecraft中没有任何更改。我不认为它是只读的,因为setAmount会抛出错误/警告?!