@SubscribeEvent public void use(PlayerUseItemEvent.Start event){ if(event.item.hasTagCompound()) if(event.item.getTagCompound().hasKey("Fidelis")) { String fidelisID = event.item.getTagCompound().getString("Fidelis"); if(event.entityPlayer.getGameProfile().getId().toString().equals(fidelisID)) return; else if(fidelisID.equals("")) { event.item.getTagCompound().setString("Fidelis", event.entityPlayer.getGameProfile().getId().toString()); event.item.getTagCompound().setString("FidelisDisplay", event.entityPlayer.getDisplayName()); } else{ event.setCanceled(true); event.duration = -1; } } }
@SubscribeEvent public void use(PlayerUseItemEvent.Tick event){ if(event.item.hasTagCompound()) if(event.item.getTagCompound().hasKey("Fidelis")) { String fidelisID = event.item.getTagCompound().getString("Fidelis"); if(event.entityPlayer.getGameProfile().getId().toString().equals(fidelisID)) return; else if(fidelisID.equals("")) { event.item.getTagCompound().setString("Fidelis", event.entityPlayer.getGameProfile().getId().toString()); event.item.getTagCompound().setString("FidelisDisplay", event.entityPlayer.getDisplayName()); } else event.setCanceled(true); } }
@SubscribeEvent public void startEating(PlayerUseItemEvent.Start event) { //Stop eating if pickiness limit is reached if(event.item.getItem() instanceof ItemFoodTFC && Settings.diminishingReturns) { FoodStatsTFC foodstats = TFC_Core.getPlayerFoodStats(event.entityPlayer); FoodRecord foodrecord = CWTFC_Core.getPlayerFoodRecord(event.entityPlayer); float deminEat = 5 * CWTFC_Core.getFoodsCount(foodrecord, event.item); if (foodstats.needFood() && deminEat != 0) return; else if(foodstats.stomachLevel <= 0) return; else if(deminEat == 0) { ChatComponentText text = new ChatComponentText("You have grown tired of this food and cannot eat it."); text.getChatStyle().setColor(EnumChatFormatting.DARK_RED).setItalic(true); event.entityPlayer.addChatComponentMessage(text); event.setCanceled(true); } } }
@SubscribeEvent public void finishItemUse(PlayerUseItemEvent.Finish event) { if (FMLCommonHandler.instance().getSide() == Side.SERVER) { EntityPlayer player = event.entityPlayer; ItemStack stack = event.item; if (Rings.proxy.manaHandler.playerHasSession(player) && !player.capabilities.isCreativeMode) { if (stack.getItem() instanceof ItemFood) { int foodPoints = ((ItemFood) stack.getItem()).func_150905_g(stack) * 2; IPlayerSession playerSession = Rings.proxy.manaHandler.getPlayerSession(player); playerSession.adjustMana(foodPoints, false); Rings.proxy.manaHandler.updatePlayerSession(playerSession, player.getEntityWorld().provider.dimensionId); } } /* if (MagicHandler.getMagicHandler().getPlayerTag(player) != null && !player.capabilities.isCreativeMode) { if (stack.getItem() instanceof ItemFood) { int foodPoints = ((ItemFood) stack.getItem()).func_150905_g(stack) * 2; Rings.pktHandler.sendToServer(new PacketModifyMp(player, foodPoints, 0)); } }*/ } }
@SubscribeEvent public void onPlayerUseItemEvent(PlayerUseItemEvent.Finish event) { if (event.item != null && event.item.getItem() == Items.brain && !event.entityPlayer.worldObj.isRemote) { KnowledgeHandler playerKnowledge = new KnowledgeHandler(event.entityPlayer.getDisplayName()); if (playerKnowledge.getKnowledgeRank() <= 20) { playerKnowledge.addKnowledgeXP(30); // TODO:Convert to lang. ChatMessageUtil.sendChatMessageToPlayer(event.entityPlayer, "You now have all the zombies' knowledge and inventions!"); } else { // TODO:Convert to lang. ChatMessageUtil.sendChatMessageToPlayer(event.entityPlayer, "You're loaded with inventions. You need to find a way to press more inventions in!"); } } }
@SubscribeEvent public void onEat(PlayerUseItemEvent.Finish event){ if(event.entityPlayer.worldObj.isRemote) return; if(event.item.getItem() instanceof ItemFood){ if(event.entityPlayer.worldObj.provider.dimensionId == -1 && event.item.getItem() != ForbiddenItems.gluttonyShard && randy.nextInt(10) < 2){ EntityItem ent = event.entityPlayer.entityDropItem(new ItemStack(ForbiddenItems.gluttonyShard, 1), 1.0F); ent.motionY += randy.nextFloat() * 0.05F; ent.motionX += (randy.nextFloat() - randy.nextFloat()) * 0.1F; ent.motionZ += (randy.nextFloat() - randy.nextFloat()) * 0.1F; } ItemStack ring = BaublesApi.getBaubles(event.entityPlayer).getStackInSlot(1); ItemStack ring2 = BaublesApi.getBaubles(event.entityPlayer).getStackInSlot(2); if((ring != null && ring.getItem() == ForbiddenItems.ringFood) || (ring2 != null && ring2.getItem() == ForbiddenItems.ringFood)){ event.entityPlayer.getFoodStats().addStats(2, 2.0F); } } }
@SubscribeEvent public void onTryToPotion(PlayerUseItemEvent.Start e) { if (e.entity.dimension == IaSFlags.dim_nyx_id && !e.entityPlayer.capabilities.isCreativeMode) { final ItemStack ite = e.item; boolean stopped = false; if (ite == null) return; else if (ite.getItem() instanceof ItemPotion) { IaSPlayerHelper.messagePlayer(e.entityPlayer, "The contents of the bottle have frozen solid."); stopped = true; } else if (ite.getItem() == Items.milk_bucket) { IaSPlayerHelper.messagePlayer(e.entityPlayer, "The milk has frozen solid."); stopped = true; } else if (ite.getItem() instanceof ItemFood && !(ite.getItem() instanceof IaSItemFood)) { IaSPlayerHelper.messagePlayer(e.entityPlayer, "It's been frozen solid. Eating it would be dangerous."); stopped = true; } if(stopped) { e.setCanceled(true); e.entityPlayer.stopUsingItem(); } } }
@SubscribeEvent public void onItemUseFinish(PlayerUseItemEvent.Finish event) { if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer && DragonPlayer.get((EntityPlayer) event.entity).isDragon()) { EntityPlayer player = (EntityPlayer) event.entity; if (event.item != null) { if (!ItemDragonEgg.isDragonFood(DragonPlayer.get(player).getDragonName(), event.item.getItem())) { LogHelper.info("onItemUseFinish: You just ate a non-dragon food!"); player.addPotionEffect(new PotionEffect(Potion.poison.id, 5*20, 1)); } else { LogHelper.info("onItemUseFinish: You just ate a dragon food!"); // Remove potions from stuff dragons can eat like rotten flesh if (player.isPotionActive(Potion.poison.id)) { player.removePotionEffect(Potion.poison.id); } if (player.isPotionActive(Potion.hunger.id)) { player.removePotionEffect(Potion.hunger.getId()); } if (event.item.getItem() == Items.rotten_flesh) { float prevSat = player.getFoodStats().getSaturationLevel(); player.getFoodStats().addStats(2, 1.0F); // Add more saturation to rotten flesh, 0.1F normally, 0.6F is cooked chicken LogHelper.info("Saturation was: " + prevSat + " is now: " + player.getFoodStats().getSaturationLevel()); } } } } }
@SubscribeEvent public void playerAteFoodEvent(PlayerUseItemEvent.Finish event) { EntityPlayer player = event.entityPlayer; World world = event.entityPlayer.worldObj; if (!world.isRemote) { if (event.item.getItem() instanceof ItemFood && this.isFoodCooked(event.item) && !(event.item.getItem() instanceof ICondiment)) { if (!event.item.hasTagCompound()) { event.item.setTagCompound(new NBTTagCompound()); } NBTTagCompound tag = event.item.getTagCompound(); if (tag.hasKey("condiment_ids") && tag.hasKey("condiment_levels")) { int[] ids = tag.getIntArray("condiment_ids"); int[] levels = tag.getIntArray("condiment_levels"); if (ids.length != levels.length) { tag.setIntArray("condiment_ids", new int[0]); tag.setIntArray("condiment_levels", new int[0]); } else if (ids.length > 0 && levels.length > 0) { ICondiment condiment = null; for (int i = 0; i < ids.length; ++i) { condiment = ModCondiments.getCondimentById(ids[i]); condiment.setLevel(levels[i]); condiment.onEaten(player, world); Utils.addExperience(player, condiment.getExp()); } } } } } }
@SubscribeEvent public void onItemUse(PlayerUseItemEvent.Start event) { if(event.entityPlayer != null) { onEvent(event.entityPlayer, event); } }
@SubscribeEvent public void stopEating(PlayerUseItemEvent.Tick event) { //Replace TFC eating mechanic with custom eating mechanic if(event.item.getItem() instanceof ItemFoodTFC && Settings.diminishingReturns) { if(event.duration <= 1) { event.entityPlayer.setCurrentItemOrArmor(0, CWTFC_Core.processEating(event.item, event.entityPlayer.worldObj, event.entityPlayer, 5, false)); event.entityPlayer.clearItemInUse(); event.setCanceled(true); } } }
public void onUpdate(PlayerUseItemEvent event) { EntityPlayer entity = event.entityPlayer; if (entity instanceof EntityPlayerMP && ((EntityPlayerMP) entity).getCurrentEquippedItem() == null) { System.out.println("null"); } System.out.println("works"); }
@SubscribeEvent public void interceptRightClick(PlayerUseItemEvent.Tick ev){ if(ev.item != null) if(ev.item.getItem() instanceof ItemBow || ev.item.getItem() instanceof ItemArcherBow) if(ev.entityPlayer.isSneaking() && PlayerRpgInventory.get(ev.entityPlayer).isBlocking()) ev.setCanceled(true); }
/** * Make sure nocked arrow is set for rendering when drawing from BG2 quiver */ @SubscribeEvent public void onBowStartDraw(PlayerUseItemEvent.Start event) { if (event.item.getItem() instanceof ItemHeroBow && ZSSPlayerInfo.get(event.entityPlayer).getNockedArrow() == null) { ItemStack arrow = getQuiverArrow(event.item, event.entityPlayer); if (arrow != null) { ZSSPlayerInfo.get(event.entityPlayer).setNockedArrow(arrow); } } }
public static int onItemUseStart(EntityPlayer player, ItemStack item, int duration) { PlayerUseItemEvent event = new PlayerUseItemEvent.Start(player, item, duration); return MinecraftForge.EVENT_BUS.post(event) ? -1 : event.duration; }
public static int onItemUseTick(EntityPlayer player, ItemStack item, int duration) { PlayerUseItemEvent event = new PlayerUseItemEvent.Tick(player, item, duration); return MinecraftForge.EVENT_BUS.post(event) ? -1 : event.duration; }
public static boolean onUseItemStop(EntityPlayer player, ItemStack item, int duration) { return MinecraftForge.EVENT_BUS.post(new PlayerUseItemEvent.Stop(player, item, duration)); }
public static ItemStack onItemUseFinish(EntityPlayer player, ItemStack item, int duration, ItemStack result) { PlayerUseItemEvent.Finish event = new PlayerUseItemEvent.Finish(player, item, duration, result); MinecraftForge.EVENT_BUS.post(event); return event.result; }
@SubscribeEvent public void interceptRightClick(PlayerUseItemEvent.Start ev){ }
/** * @param event */ @SubscribeEvent public void eatGoldenApple(PlayerUseItemEvent.Finish event) { EntityPlayer player = event.entityPlayer; if (ConfigHandler.BACKPACK_ABILITIES) { if (event.item.getItem() instanceof ItemAppleGold && //((ItemAppleGold) event.item.getItem()).getRarity(event.item) == EnumRarity.epic && Wearing.isWearingTheRightBackpack(player, "Rainbow")) { InventoryBackpack inv = new InventoryBackpack(Wearing.getWearingBackpack(player)); if (inv.getLastTime() > 0) return; inv.setLastTime(Utils.secondsToTicks(150)); inv.dirtyTime(); if (!player.worldObj.isRemote) { String nyanString = EnumChatFormatting.RED + "N" + EnumChatFormatting.GOLD + "Y" + EnumChatFormatting.YELLOW + "A" + EnumChatFormatting.GREEN + "N" + EnumChatFormatting.AQUA + "C" + EnumChatFormatting.BLUE + "A" + EnumChatFormatting.DARK_PURPLE + "T"; player.addChatComponentMessage(new ChatComponentText(nyanString)); ModNetwork.sendToNearby(new EntitySoundPacket.Message(EntitySoundPacket.NYAN_SOUND, player), player); } } } if (event.item.getItem() instanceof ItemPotion && (event.item.getItem()).getDamage(event.item) == 0) { if (!player.worldObj.isRemote) { FluidEffectRegistry.executeFluidEffectsForFluid(FluidRegistry.WATER, player, player.getEntityWorld()); } } }
@SubscribeEvent public void onUseItem(PlayerUseItemEvent.Finish e){ if(e.entityPlayer.worldObj.isRemote) return; action(e.entityPlayer); }
@SubscribeEvent public void onUseItem(PlayerUseItemEvent.Finish e){ if(e.entityPlayer.worldObj.isRemote) return; derpInv(e.entityPlayer); }