use of com.yogpc.qp.version.VersionUtil in project QuarryPlus by Kotori316.
the class QuarryPlus method message.
/**
* Message key must be either {@code IMC_RemoveRecipe} or {@code IMC_AddRecipe}.
* Message value must be NBTTag.
*
* @param event event
*/
@Mod.EventHandler
public void message(FMLInterModComms.IMCEvent event) {
event.getMessages().forEach(imcMessage -> {
NBTTagCompound nbtValue = imcMessage.getNBTValue();
Function<NBTTagCompound, ItemStack> toStack = VersionUtil::fromNBTTag;
if (Optionals.IMC_Remove.equals(imcMessage.key)) {
WorkbenchRecipes.removeRecipe(ItemDamage.apply(toStack.apply(nbtValue)));
} else if (Optionals.IMC_Add.equals(imcMessage.key)) {
Function<ItemStack, IntFunction<ItemStack>> toFunc = stack -> (IntFunction<ItemStack>) integer -> ItemHandlerHelper.copyStackWithSize(stack, VersionUtil.getCount(stack) * integer);
NBTTagList list = nbtValue.getTagList(Optionals.IMC_Add, Constants.NBT.TAG_COMPOUND);
ItemDamage result = ItemDamage.apply(toStack.apply(list.getCompoundTagAt(0)));
List<IntFunction<ItemStack>> functionList = VersionUtil.nbtListStream(list).skip(1).map(toStack.andThen(toFunc)).collect(Collectors.toList());
WorkbenchRecipes.addListRecipe(result, nbtValue.getInteger(Optionals.IMC_Energy), functionList, true, WorkbenchRecipes.UnitRF());
}
});
}
Aggregations