use of WayofTime.bloodmagic.iface.IUpgradeTrainer in project BloodMagic by WayofTime.
the class CraftingHandler method onAnvil.
// Handles crafting of: Revealing Upgrade Tome, Elytra Upgrade Tome, Combining Upgrade Tomes, Setting Upgrade for Trainer
@SubscribeEvent
public static void onAnvil(AnvilUpdateEvent event) {
if (event.getLeft().getItem() == RegistrarBloodMagicItems.SIGIL_HOLDING) {
if (event.getRight().getItem() == Items.NAME_TAG) {
ItemStack output = event.getLeft().copy();
if (!output.hasTagCompound())
output.setTagCompound(new NBTTagCompound());
output.getTagCompound().setString(Constants.NBT.COLOR, event.getRight().getDisplayName());
event.setCost(1);
event.setOutput(output);
return;
}
if (event.getRight().getItem() == Items.DYE) {
EnumDyeColor dyeColor = ItemBanner.getBaseColor(event.getRight());
ItemStack output = event.getLeft().copy();
if (!output.hasTagCompound())
output.setTagCompound(new NBTTagCompound());
output.getTagCompound().setString(Constants.NBT.COLOR, String.valueOf(Utils.DYE_COLOR_VALUES.getOrDefault(dyeColor, 0)));
event.setCost(1);
event.setOutput(output);
return;
}
}
if (event.getLeft().getItem() == Items.BOOK && event.getRight().getItem() == Items.ELYTRA && !event.getRight().isItemDamaged()) {
ItemStack output = new ItemStack(RegistrarBloodMagicItems.UPGRADE_TOME);
output = NBTHelper.checkNBT(output);
ItemHelper.LivingUpgrades.setKey(output, BloodMagic.MODID + ".upgrade.elytra");
ItemHelper.LivingUpgrades.setLevel(output, 1);
event.setCost(30);
event.setOutput(output);
return;
}
if (event.getLeft().getItem() == RegistrarBloodMagicItems.UPGRADE_TOME && event.getRight().getItem() == RegistrarBloodMagicItems.UPGRADE_TOME) {
LivingArmourUpgrade leftUpgrade = ItemHelper.LivingUpgrades.getUpgrade(event.getLeft());
if (leftUpgrade != null && !leftUpgrade.isDowngrade() && ItemHelper.LivingUpgrades.getKey(event.getLeft()).equals(ItemHelper.LivingUpgrades.getKey(event.getRight()))) {
int leftLevel = ItemHelper.LivingUpgrades.getLevel(event.getLeft());
int rightLevel = ItemHelper.LivingUpgrades.getLevel(event.getRight());
if (leftLevel == rightLevel && leftLevel < leftUpgrade.getMaxTier() - 1) {
ItemStack outputStack = event.getLeft().copy();
ItemHelper.LivingUpgrades.setLevel(outputStack, leftLevel + 1);
event.setCost(leftLevel + 2);
event.setOutput(outputStack);
return;
}
}
}
if (event.getLeft().getItem() instanceof IUpgradeTrainer && event.getRight().getItem() == RegistrarBloodMagicItems.UPGRADE_TOME) {
LivingArmourUpgrade rightUpgrade = ItemHelper.LivingUpgrades.getUpgrade(event.getRight());
if (rightUpgrade != null) {
String key = ItemHelper.LivingUpgrades.getKey(event.getRight());
ItemStack outputStack = event.getLeft().copy();
List<String> keyList = new ArrayList<>();
keyList.add(key);
if (((IUpgradeTrainer) event.getLeft().getItem()).setTrainedUpgrades(outputStack, keyList)) {
event.setCost(1);
event.setOutput(outputStack);
}
}
}
}
Aggregations