Posted May 12, 20241 yr Hi, can anybody tell me what's wrong? public class SoulDrinkerItem extends Item { public SoulDrinkerItem(Properties pProperties) { super(pProperties); } @Override public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) { if (entity instanceof Player){ Player victim = (Player) entity; if(!victim.isDeadOrDying() && victim.getHealth()>0){ victim.setHealth(0); return true; } } return false; } @Override public void setDamage(ItemStack stack, int damage) { super.setDamage(stack, 0); } } The code above is the custom item class. I'm trying to make a Sword-of-the-Cosmos-like item that basically does .setHealth(0) for every single entity it hits. When I go into the game, the attack damage is just 1. Edited May 12, 20241 yr by ANtonYL
May 12, 20241 yr It looks like you're only setting the health if the thing you are hitting is a player. 8 hours ago, ANtonYL said: if (entity instanceof Player){ Player victim = (Player) entity; if(!victim.isDeadOrDying() && victim.getHealth()>0){ victim.setHealth(0); return true; } }
May 12, 20241 yr Author 2 hours ago, scientistknight1 said: It looks like you're only setting the health if the thing you are hitting is a player. Ok. Thanks. by the way, will this crash in any circumstances? public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) { if (entity instanceof LivingEntity){ LivingEntity victim = (LivingEntity) entity; if(!victim.isDeadOrDying() && victim.getHealth()>0){ victim.setHealth(0); return true; } } return false; }
May 12, 20241 yr Author How can I add drops when killing an entity? Now there are no drops. How can I add an @override to change the attack speed to 1.6 and show "when in main hand...attack damage,...attack speed"? also, how can I make the item enchantable?
May 13, 20241 yr To ensure that the entity drops resources in the usual way, try using the .kill() method instead of .setHealth(int); that should work better. Try making your class extend SwordItem to use all the standard sword infrastructure. Just make sure to add super calls at the top of all methods you override if you want to keep the existing behavior as well.
May 13, 20241 yr Author Thank you so much. Also, is it possible to make the name of the sword constantly changing colors and show "+infinity attack damage "?
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.