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've got a "wand" item that, on right-click, I wish to be able to inflict various things on mobs: set on fire or apply a potion effect to them. My two attempts at doing this are below.

 

Apply a poison potion effect:

    @Nonnull
    @Override
    public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemstack, World world, EntityPlayer player, EnumHand hand) {
        RayTraceResult target = Minecraft.getMinecraft().objectMouseOver;
        if (target.typeOfHit == RayTraceResult.Type.ENTITY) {
            if (target.entityHit instanceof EntityLivingBase) {
                EntityLivingBase entitylivingbase = (EntityLivingBase) target.entityHit;
                Potion potion = Potion.REGISTRY.getObject(new ResourceLocation("poison"));
                PotionEffect potioneffect = new PotionEffect(potion, 50, 1);
                if (potion.isInstant()) {
                    potion.affectEntity(null, null, entitylivingbase, potioneffect.getAmplifier(), 0.5D);
                } else {
                    entitylivingbase.addPotionEffect(potioneffect);
                }
            }
        }
        return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
    }

The result of the above is that the potion effect doesn't appear to be applied at all.

 

Changing the code to instead set the entity on fire:

    @Nonnull
    @Override
    public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemstack, World world, EntityPlayer player, EnumHand hand) {
        RayTraceResult target = Minecraft.getMinecraft().objectMouseOver;
        if (target.typeOfHit == RayTraceResult.Type.ENTITY) {
            target.entityHit.setFire(4);
        }
        return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
    }

This results in a brief flash of fire effect on the entity, but it does not remain on fire for the full 4 seconds that I specify. I know that I've invoked the setFire method correctly because if I do so in a hitEntity() override like so:

    public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
        target.setFire(4);
        return true;
    }

The entity stays on fire!

Minecraft.getMinecraft().objectMouseOver;

Is client side only, meaning since the server doesn't know about this it can't do it. Meaning it is reset next tick for the client.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

OK, thanks. I'm now looking into how to send packets from the client to the server!

 

Solution: I ended up implementing InvokeWandMessage which encoded the RayTraceResult generated by PythonWandItem and sent it to the server for actioning. Works!!

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.