Forge1.12.2,怎么在作出一个特定合成时触发一个事件?
比如,让玩家在合成黄金剑的时候,有几率获得不可破坏的剑
拜托各位帮帮忙!
Forge1.12.2,怎么在作出一个特定合成时触发一个事件?
比如,让玩家在合成黄金剑的时候,有几率获得不可破坏的剑
拜托各位帮帮忙!
可以通过注册一个IRecipe实现在作出特定合成时触发一个事件
public class MyRecipe implements IRecipe {
@Override
public boolean matches(InventoryCrafting inv, World world) {
// 判断当前合成是否符合条件
// 如果符合条件,返回true,否则返回false
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
// 返回合成结果
ItemStack result = new ItemStack(Items.DIAMOND);
// 触发一个自定义事件
MinecraftForge.EVENT_BUS.post(new MyEvent());
return result;
}
}
// 注册合成
GameRegistry.addRecipe(new MyRecipe());