Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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);
    }
}

 

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.