Posted February 12, 20169 yr Im trying to add a potion effect to an entity when the entity is attacked. Problem is when you attack the weaker mobs chickens and sheep. They are killed and the potion effect is not added. But on cows which take 2 hits to kill the first hit does damage and adds the potion effect then the second one kills it. I am trying to have to potion effect applied before the entity is killed. If you can help that would be great here is my EventHandler for the potion @SubscribeEvent public void onEntityUpdate(LivingUpdateEvent event){ if(event.entityLiving.isPotionActive(PotionRegistry.soulBindPot)){ if(event.entityLiving.worldObj.rand.nextInt(20) == 0){ if(event.entityLiving.getHealth() == 0){ System.out.println("Killed while Soul Bind was in effect"); }else{ } } if(event.entityLiving.getActivePotionEffect(PotionRegistry.soulBindPot).getDuration() == 0){ event.entityLiving.removePotionEffect(PotionRegistry.soulBindPot.id); } } } @SubscribeEvent public void onEntityDeath(LivingDeathEvent event){ if(event.entityLiving.isPotionActive(PotionRegistry.soulBindPot)){ if(event.source.damageType.equals("player")){ EntityPlayer player = (EntityPlayer)event.source.getSourceOfDamage(); int soul = 0; if(event.entityLiving instanceof EntityPlayer){ //Black Souls soul = 5; }else{ if(event.entityLiving.getMaxHealth() <= 4){ //Petty Souls soul = 0; }else if(event.entityLiving.getMaxHealth() <= 8 && event.entityLiving.getMaxHealth() > 4 ){ //Lesser Souls soul = 1; }else if(event.entityLiving.getMaxHealth() <= 20 && event.entityLiving.getMaxHealth() > 8 ){ //Common Souls soul = 2; }else if(event.entityLiving.getMaxHealth() <= 100 && event.entityLiving.getMaxHealth() > 20 ){ //Greater Souls soul = 3; }else if(event.entityLiving.getMaxHealth() > 100 ){ //Grand Souls soul = 4; } } switch(soul){ case 0: if(!player.inventory.hasItem(ItemRegistry.pettySoulGem)){ player.addChatComponentMessage(new ChatComponentText("No empty Petty Soul Gem")); break; } for(int i = 0; i < player.inventory.mainInventory.length; i ++){ if(player.inventory.mainInventory[i] != null && player.inventory.mainInventory[i].getItem().equals(ItemRegistry.pettySoulGem)){ for(int j = 0; j < player.inventory.mainInventory.length; j++){ if(player.inventory.mainInventory[j] == null){ player.addChatComponentMessage(new ChatComponentText("Soul Captured")); player.inventory.consumeInventoryItem(ItemRegistry.pettySoulGem); player.inventory.setInventorySlotContents(j, new ItemStack(ItemRegistry.pettySoulGemFilled)); break; } } }else{ System.out.println("Error: "); } } break; case 1: if(!player.inventory.hasItem(ItemRegistry.lesserSoulGem)){ player.addChatComponentMessage(new ChatComponentText("No empty Lesser Soul Gem")); break; } for(int i = 0; i < player.inventory.mainInventory.length; i ++){ if(player.inventory.mainInventory[i] != null && player.inventory.mainInventory[i].getItem().equals(ItemRegistry.lesserSoulGem)){ for(int j = 0; j < player.inventory.mainInventory.length; j++){ if(player.inventory.mainInventory[j] == null){ player.addChatComponentMessage(new ChatComponentText("Soul Captured")); player.inventory.consumeInventoryItem(ItemRegistry.lesserSoulGem); player.inventory.setInventorySlotContents(j, new ItemStack(ItemRegistry.lesserSoulGemFilled)); break; } } }else{ System.out.println("Error: "); } } break; case 2: if(!player.inventory.hasItem(ItemRegistry.commonSoulGem)){ player.addChatComponentMessage(new ChatComponentText("No empty Common Soul Gem")); break; } for(int i = 0; i < player.inventory.mainInventory.length; i ++){ if(player.inventory.mainInventory[i] != null && player.inventory.mainInventory[i].getItem().equals(ItemRegistry.commonSoulGem)){ for(int j = 0; j < player.inventory.mainInventory.length; j++){ if(player.inventory.mainInventory[j] == null){ player.addChatComponentMessage(new ChatComponentText("Soul Captured")); player.inventory.consumeInventoryItem(ItemRegistry.commonSoulGem); player.inventory.setInventorySlotContents(j, new ItemStack(ItemRegistry.commonSoulGemFilled)); break; } } }else{ System.out.println("Error: "); } } break; case 3: if(!player.inventory.hasItem(ItemRegistry.greaterSoulGem)){ player.addChatComponentMessage(new ChatComponentText("No empty Greater Soul Gem")); break; } for(int i = 0; i < player.inventory.mainInventory.length; i ++){ if(player.inventory.mainInventory[i] != null && player.inventory.mainInventory[i].getItem().equals(ItemRegistry.greaterSoulGem)){ for(int j = 0; j < player.inventory.mainInventory.length; j++){ if(player.inventory.mainInventory[j] == null){ player.addChatComponentMessage(new ChatComponentText("Soul Captured")); player.inventory.consumeInventoryItem(ItemRegistry.greaterSoulGem); player.inventory.setInventorySlotContents(j, new ItemStack(ItemRegistry.greaterSoulGemFilled)); break; } } }else{ System.out.println("Error: "); } } break; case 4: if(!player.inventory.hasItem(ItemRegistry.grandSoulGem)){ player.addChatComponentMessage(new ChatComponentText("No empty Grand Soul Gem")); break; } for(int i = 0; i < player.inventory.mainInventory.length; i ++){ if(player.inventory.mainInventory[i] != null && player.inventory.mainInventory[i].getItem().equals(ItemRegistry.grandSoulGem)){ for(int j = 0; j < player.inventory.mainInventory.length; j++){ if(player.inventory.mainInventory[j] == null){ player.addChatComponentMessage(new ChatComponentText("Soul Captured")); player.inventory.consumeInventoryItem(ItemRegistry.grandSoulGem); player.inventory.setInventorySlotContents(j, new ItemStack(ItemRegistry.grandSoulGemFilled)); break; } } }else{ System.out.println("Error: "); } } break; case 5: if(!player.inventory.hasItem(ItemRegistry.blackSoulGem)){ player.addChatComponentMessage(new ChatComponentText("No empty Black Soul Gem")); break; } for(int i = 0; i < player.inventory.mainInventory.length; i ++){ if(player.inventory.mainInventory[i] != null && player.inventory.mainInventory[i].getItem().equals(ItemRegistry.blackSoulGem)){ for(int j = 0; j < player.inventory.mainInventory.length; j++){ if(player.inventory.mainInventory[j] == null){ player.addChatComponentMessage(new ChatComponentText("Soul Captured")); player.inventory.consumeInventoryItem(ItemRegistry.blackSoulGem); player.inventory.setInventorySlotContents(j, new ItemStack(ItemRegistry.blackSoulGemFilled)); break; } } }else{ System.out.println("Error: "); } } break; default: } } } }
February 12, 20169 yr Author I have a sword that is a debug item. It extends itemSword andbeach time the entity is hit it adds to potion effect. And all the different gems are to be similar to skyrim. And yes ik the code is messy. I just wanted to get it all to work before trying to screw with it
February 12, 20169 yr its way better to clean ur code FIRST and then extend the functionality. otherway you will just mess up
February 12, 20169 yr Author The potion does nothing. I have a check to see if a mob has the potion effect and if they do take an empty soul gem and fill it when they die.
February 12, 20169 yr Any reason you don't check to see if the entity was killed by the player? Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
February 12, 20169 yr Author Because i am making it an enchant and potion and spell. It will only capture souls if you have soul trapon a weapon in a potion or as a spell
February 12, 20169 yr You know you can check for the player's active weapon in the EntityDeadEvent, right? As well as any other property active on the player. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
February 13, 20169 yr Author i know that. Back to the point, I want my event to take an empty soul gem and fill it, I want the potion to be added to the chickens etc before the damage is applied to them, at the moment it seems to apply the potion effect after the damage is applied therefore the chickens and lesser health mobs are killed then the potion effect is added to their dying corpse. I am looking for a way to change that. the main reason that I want this to be a potion effect is that it will not only be on a sword, but on any weapon, a potion or spell. so that you can toss the potion or spell and kill them with any weapon.
February 13, 20169 yr Author This effect will be a potion a spell and an enchantment that can go on any weapon. Just like in skyrim it will depending on the level have a certain duration. Ie if target dies in 5 seconds fills gem. I know i can check the weapon the player is holding but there wont always be a weapon that has this effect. Long story short i need help applying the potion effect before the entity dies. The point of this topic is not about my methods or reasons.
February 13, 20169 yr Author This effect will be a potion a spell and an enchantment that can go on any weapon.Again, what does the potion do?Just like in skyrim it will depending on the level have a certain duration.I do not know Skyrim. What level? What will have a duration?Ie if target dies in 5 seconds fills gem.Within 5 seconds of what?Long story short i need help applying the potion effect before the entity dies.Dies from what? You have not described this accurately at all.The point of this topic is not about my methods or reasons. Yes it is. as I have said, the potion does nothing on its own. I have the event handler to check if the entity has the sould bind effect. if it does then the event handler will fill a soul gem. the level is in regards to the enchantment level. the higher the level the longer the duration of the soul bind potion effect. if the target dies in 5 seconds after the potion effect is applied then it will fill a gem. if the entity dies from anything, player, potion effects (poison harming etc) other players or entities, again I fail to see how any of this has to do with having the potion effect applied before damage is, when the entity dies the event is called and since the potion effect has not been applied it wont fill a gem, I want to rectify that and apply the damage after the entity gets the potion effect
February 13, 20169 yr Author I am going to make a potion as i have said and the damage is the sword or weapon the enchant will be on.
February 13, 20169 yr Sounds like the potion effect is a marker of some sort to say that "critter was whacked by something special".
February 13, 20169 yr Author oddly enough, once I made the enchant apply the potion effect, then guess what, it works. so yeah. nvm on all this
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.