Posted May 30, 20232 yr I am trying to make my inventoryTick damage all entities in a 5 block radius constantly and apply particles but the damage is not working. Does anyone know how to make this work? public class ElectricPowerCharm extends Item { public ElectricPowerCharm(Properties properties) { super(properties); } private int delay = 200; private int range = 5; // Range in blocks private float damageAmount = 2.0f; // Amount of damage to apply per tick @Override public void inventoryTick(ItemStack stack, Level level, Entity entity, int itemSlot, boolean isSelected) { if (level.isClientSide && entity instanceof Player) { Player player = (Player) entity; double posX = player.getX(); double posY = player.getY() + 1.0; // Offset particles slightly above the player's head double posZ = player.getZ(); AABB aabb = new AABB(posX - range, posY - range, posZ - range, posX + range, posY + range, posZ + range); for (Entity targetEntity : level.getEntities(player, aabb)) { if (targetEntity instanceof LivingEntity) { LivingEntity livingEntity = (LivingEntity) targetEntity; double entityX = livingEntity.getX(); double entityY = livingEntity.getY() + 0.7d; double entityZ = livingEntity.getZ(); for (int i = 1; i <= 50; i++) { double motionX = level.random.nextGaussian() + 1d; double motionY = level.random.nextGaussian() + 1d; double motionZ = level.random.nextGaussian() + 1d; level.addParticle(ParticleTypes.ELECTRIC_SPARK, entityX, entityY, entityZ, motionX, motionY, motionZ); } livingEntity.hurt(DamageSource.playerAttack(player), damageAmount); // Apply damage } } } super.inventoryTick(stack, level, entity, itemSlot, isSelected); } }
May 30, 20232 yr 2 hours ago, Fennx1000 said: if (level.isClientSide && entity instanceof Player) { Damage is applied on the server. Apply damage on the server and then use #sendParticles to render it on the client. 2 hours ago, Fennx1000 said: private int delay = 200; private int range = 5; // Range in blocks private float damageAmount = 2.0f; // Amount of damage to apply per tick You shouldn't do this btw since there will only be one instance of your item, so these values will be shared across all unless you register a new item.
May 31, 20232 yr 22 hours ago, Fennx1000 said: wait do u want me to make a packet... I didn't say that. I said check if the level is on the server, then call #sendParticles to have the particles appear on the client. #sendParticles already sends a packet containing the particles to the necessary client.
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.