制作黄色不闪光药水

Create yellow non-shimmering potion

在 Minecraft Forge mod 中,我想创建一个看起来是黄色但不闪烁的部分(就像 "Water Bottle" 药水的黄色版本)。

我目前正在做这样的事情(省略不相关的位):

@Mod(modid=modId, name="Lemonade Mod", version="1.0")
public class LemonadeMod {
    ...
    private static final Potion POTION_LEMONADE = new PotionHealth(false, 0xFF_FF_FF_55);
    private static final PotionType POTION_TYPE_LEMONADE = new PotionType("lemonade", new PotionEffect(POTION_LEMONADE));
    ...    
    @Mod.EventBusSubscriber
    public static class RegistrationHandler {    
        @SubscribeEvent
        public static void registerPotionTypes(RegistryEvent.Register<PotionType> event) {
            event.getRegistry().register(POTION_TYPE_LEMONADE.setRegistryName("lemonade"));
        }
    }
}

这会产生黄色药水,但它会闪烁。有什么办法可以消除闪光效果吗?

而不是使用原版的系统来酿造药水:

Diesieben07 said:
PotionType is a potion that can be brewed, Potion is just the "type of effect."

根据该线程的信息,只需创建一个普通项目 class 并覆盖此方法,如下所示:

@Override
public EnumAction getItemUseAction(ItemStack stack)
{
    return EnumAction.DRINK;
}

这处理微光,因为 ItemPotion 覆盖 public boolean hasEffect(ItemStack stack) 为 return 当药水有任何效果时为真(而你不希望那样)。

然后你所要做的就是在玩家喝下你的物品时通过覆盖 onItemUseFinish 给他们 PotionEffect。您可以查看 ItemPotion 以获取如何执行此操作的示例(尽管您不需要大量代码)。

根据 Minecraft Forge forum post 的回复,此 class 定义了一个项目,当您右键单击时,它的行为类似于药水:

import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;
import java.util.List;

public class ItemLemonade extends Item {

    /**
     * This method needs to be overridden because otherwise the duration is too short,
     * the potion consumption won't animate correctly, and there won't be any sound
     */
    @Override
    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 32;
    }

    @Override
    public EnumAction getItemUseAction(ItemStack stack) {
        return EnumAction.DRINK;
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        playerIn.setActiveHand(handIn);
        return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
        tooltip.add("Delicious, refreshing lemonade");
    }
}