@SubscribeEvent public void setUpgradeChance(AnvilRepairEvent event) { ItemStack output = event.getItemResult(); EntityPlayer player = event.getEntityPlayer(); if (output == null) return; if (player == null) return; if (player.worldObj.isRemote) return; if (output.getItem() instanceof IBookUpgradeable) { int upgradelevel = NBTUtils.getInt(output, ItemGeneric.TAG_UPGRADE, -1); if (upgradelevel == 10) { Random rand = new Random(); if (rand.nextBoolean() == false && !player.worldObj.isRemote) { player.addChatMessage(new TextComponentString(TextFormatting.RED + "You attempt to refine this item, but it breaks..")); output.stackSize = 0; } } } }
/** * Fired when the player removes a "repaired" item from the Anvil's Output slot. * */ @SubscribeEvent public void onAnvilRepair(AnvilRepairEvent event) { Item item1 = event.left == null ? null : event.left.getItem(); Item item2 = event.right == null ? null : event.right.getItem(); Item pumpkin = Item.getItemFromBlock(Blocks.pumpkin); // Check if the player combined a pumpkin and an enchanted book if (event.output.getItem() == pumpkin && (item1 == pumpkin || item1 == Items.enchanted_book) && (item2 == pumpkin || item2 == Items.enchanted_book)) { // Gives the achievement event.entityPlayer.triggerAchievement(MyAchievements.EnchantPumpkin); } }
@SubscribeEvent public void onRepairUpdate(AnvilRepairEvent event) { ItemStack right = event.right; ItemStack left = event.left; if (right.getItem().equals(TwistedSouls.Registry.SHARD) && left.getItem().equals(TwistedSouls.Registry.SHARD) && right.getItemDamage() != 0) { int rightKill = right.getMaxDamage() - right.getItemDamage(); int leftKill = left.getMaxDamage() - left.getItemDamage(); event.output.setTagCompound(right.getTagCompound()); event.output.setItem(TwistedSouls.Registry.SHARD); event.output.setItemDamage(right.getMaxDamage() - (rightKill + leftKill)); } }
public static float onAnvilRepair(EntityPlayer player, ItemStack output, ItemStack left, ItemStack right) { AnvilRepairEvent e = new AnvilRepairEvent(player, left, right, output); MinecraftForge.EVENT_BUS.post(e); return e.getBreakChance(); }
public static float onAnvilRepair(EntityPlayer player, ItemStack output, ItemStack left, ItemStack right) { AnvilRepairEvent e = new AnvilRepairEvent(player, left, right, output); MinecraftForge.EVENT_BUS.post(e); return e.breakChance; }
@SubscribeEvent public void onAnvilRepair(AnvilRepairEvent event) { }