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 a potion that kills a player/entity instantly. I have some code but it doesn't do anything. Any help?

 

@SubscribeEvent
public void onPotionThrow(LivingUpdateEvent event){
	if (event.entityLiving.isPotionActive(MainClass.instaKill)){

		event.entityLiving.setDead();
}

}

 

Don't tell me to learn the basics of java, I already know.

That code, if it ran, would kill the entity that throws any splash potion

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

I assume this is wrong too?

 

@SubscribeEvent
public void onEffect(LivingUpdateEvent event){
	if (event.entityLiving.isPotionActive(PupletItems.potionInstaKill)){

		event.entityLiving.attackEntityFrom(DamageSource.magic, 1.0F);
}

}

Don't tell me to learn the basics of java, I already know.

Is it doing what you want? No? Then yes, it's wrong. Start adding system.out () statements to see what is going on.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Still don't know what to do :/ Does it need to be similar to the affectEntity code in the Potion class

 

public void affectEntity(EntityLivingBase par1EntityLivingBase, EntityLivingBase par2EntityLivingBase, int par3, double par4)
    {
        int j;

        if ((this.id != heal.id || par2EntityLivingBase.isEntityUndead()) && (this.id != harm.id || !par2EntityLivingBase.isEntityUndead()))
        {
            if (this.id == harm.id && !par2EntityLivingBase.isEntityUndead() || this.id == heal.id && par2EntityLivingBase.isEntityUndead())
            {
                j = (int)(par4 * (double)(6 << par3) + 0.5D);

                if (par1EntityLivingBase == null)
                {
                    par2EntityLivingBase.attackEntityFrom(DamageSource.magic, (float)j);
                }
                else
                {
                    par2EntityLivingBase.attackEntityFrom(DamageSource.causeIndirectMagicDamage(par2EntityLivingBase, par1EntityLivingBase), (float)j);
                }
            }
        }
        else
        {
            j = (int)(par4 * (double)(4 << par3) + 0.5D);
            par2EntityLivingBase.heal((float)j);
        }
    }

Don't tell me to learn the basics of java, I already know.

  • Author

Don't just copy paste code. You don't need an event handler, your Potion class gives you all the hooks you need:

 

isInstant

- if this returns true your potion does not apply a PotionEffect to the entity, it just acts as a one-off effect (like instant health).

 

affectEntity

- Called to apply the one-off effect if

isInstant

is true

 

isReady

- Called every tick if your potion is active on an entity (

isInstant

must be false). Arguments are

ticksLeft

and

amplifier

. If this method returns true,

performEffect

is called so it can perform the effect this tick.

 

Edit: Oh, and this:

Don't tell me to learn the basics of java, I already know.
cannot be taken seriously at all if you produce a thread like this.

What does this have to do with basic java.  Also, just because I did something wrong, doesn't mean I copy pasted something

Don't tell me to learn the basics of java, I already know.

  • Author

Well yes it was copy in paste, but if you read the question, I was asking if I should use something similar to that code.

Don't tell me to learn the basics of java, I already know.

  • Author

Also, I found what you described, understand what it does in vanilla, but still don't know what to do in my case

Don't tell me to learn the basics of java, I already know.

  • Author

Not working.  Not sure if it's because I'm applying the effect via command.  If so, how do I create the physical splash potion.  Is it just an Item

 

@Override
public boolean isInstant()
    {
        return true;
    }


public void affectEntity(EntityLivingBase entity1, EntityLivingBase entity2, int par3, double par4){

	entity2.setDead();
}

Don't tell me to learn the basics of java, I already know.

  • Author

I'm also having a hard time creating the actual potion item itself.  When I try to set its creative tab, it adds all the potions to my creative tab

Don't tell me to learn the basics of java, I already know.

Share the code you are having problems with. You seem to have two issues?

1) creating the actual potion item itself (are you having problems with the Potion class?)

2) something to do with 'adds all the potions to my creative tab'. Not sure what that means....

  • Author

Sorry, here, this is the actual ItemPotion class I made for the splash potion. And what I mean by the creative tab is, I have my own creative tab, and whenever I add this to that creative tab, it adds all potions that actually exist in vanilla, to my tab

package com.puplet.items;

import com.puplet.blocks.PupletBlocks;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;

public class InstaPotion extends ItemPotion{

public InstaPotion(){


}

 public EnumAction getItemUseAction(ItemStack par1ItemStack)
    {
        return EnumAction.drink;
    }

 public static boolean isSplash(int par0)
    {
        return true;
    }


}

Don't tell me to learn the basics of java, I already know.

  • Author

I think I may be missing something here, because I see no answer in getSubItems. Please point out what you are talking about

Don't tell me to learn the basics of java, I already know.

  • Author

So why when I use this.setCreativeTabs it adds all vanilla potions to my tab

Don't tell me to learn the basics of java, I already know.

because: ItemPotion#getSubItems adds all possible potions to the list.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Why are you making a custom potion effect?

You can just use /effect player 7 1 100 to give somebody a good strike.

Or in code : entity.setDead()

  • Author

You're right, what I really wanted to do was to just make it into a potion

Don't tell me to learn the basics of java, I already know.

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.