Jump to content

[1.18.1] Custom Items and Splash Potions


Will6

Recommended Posts

What is the best way to make a splash potion drop on the ground upon right clicking with a custom item? I overrode use but I'm not quite sure about how to get the splash potion to drop.

import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.projectile.ThrowableProjectile;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.*;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.Objects;

public class TitaniumLongswordItem extends SwordItem {

    private static Properties properties = new Item.Properties().tab(CreativeModeTab.TAB_COMBAT);

    public static Item INSTANCE = new TitaniumLongswordItem(Tiers.IRON, 17, 2147483646, properties).setRegistryName(BaseMod.MODID,"titaniumlongsword");
    public TitaniumLongswordItem(Tier tier, int attackDamageIn, float attackSpeedIn, Properties properties) {
        super(tier, attackDamageIn, attackSpeedIn, properties);
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level level, Player playerIn, InteractionHand handIn){
        ItemStack itemstack = playerIn.getItemInHand(handIn);
        BlockPos location = Utils.getBlockAtCursor(playerIn, 20.0d, true);
        Entity entity = new ThrownPotion(EntityType.POTION);// new MobEffectInstance(MobEffects.HARM);
        //float explosionRadius = 0f;
        if(location != null){
            //Utils.strikeLightning(level, location);
            //Utils.createExplosion(level, location, explosionRadius);
            Utils.spawnEntity(level, entity, location);
        }
        BlockPos blockPos = Utils.getBlockAtCursor(playerIn, 20.0d, true);
        if(blockPos != null){
            playerIn.teleportTo(blockPos.getX(), blockPos.getY()+1, blockPos.getZ());
            playerIn.fallDistance = 2.0F;
            playerIn.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 50, 150));
            playerIn.addEffect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 400, 2));
            return InteractionResultHolder.pass(itemstack);
        }
        return InteractionResultHolder.pass(itemstack);
    }
}

 

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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