Posted May 5, 201411 yr Hello, it's Red Lapis. I'm currently working on my first mod. I won't say much about it except that it adds a lot of swords. I want one of these swords to repair itself slightly after killing a mob or player. I've been through the ItemSword.class to find what makes it affect durability when hitting an entity, but can't figure out how to make it affect durability when killing an entity. I assume that it is the entity that decides to die when it reaches 0 or less health and not the decision of what damages the entity to find its health, calculate if the health would be 0 or less after it hits, and then tell the entity to die if so.
May 5, 201411 yr Override the hitEntity method. Example: @Override public boolean hitEntity(ItemStack itemStack, EntityLivingBase living1, EntityLivingBase living2) { if (itemStack.getItemDamage() > 0) { itemStack.setItemDamage(itemStack.getItemDamage() - 1); } return true; } if (user.hasKnowledgeOfJava) { if (user.question.hasCode) { return interpetHelpfulResponse(user.getQuestion()); } else { return "Could you post your code please?"; } } else { return "Learn some freaking Java!"; }
May 5, 201411 yr Author The code example you showed me would be helpful for repairing the sword upon hitting and dealing damage to an entity, but I was wondering if there is a way for it to check whether the entity died from the hit or not. Do I have to reference to that specific mob?
May 5, 201411 yr The code example you showed me would be helpful for repairing the sword upon hitting and dealing damage to an entity, but I was wondering if there is a way for it to check whether the entity died from the hit or not. Do I have to reference to that specific mob? Just check if the entity hitted is alive .isEntityAlive() @Override public boolean hitEntity(ItemStack itemStack, EntityLivingBase living1, EntityLivingBase living2) { if (!living1.isEntityAlive()) { if (itemStack.getItemDamage() > 0) { itemStack.setItemDamage(itemStack.getItemDamage() - 1); } } return true; }
May 5, 201411 yr Author Thank you, SackCastellon. I didn't think it would be so easy! Edit: Although it's useful in some cases, it's not what i'm looking for. The .isEntityAlive() checks when the entity is hit, not after whether it is still alive is calculated. striking the dead body before it despawns is the only way for the check to return false.I need something that checks whether the entity would still be alive or not after it is hit. Is there a way for the item to find the entity's initial health before the damage is calculated? Edit: Never mind. I added an else statement and now it does what I want.
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.