Minecraft 1.12.2模组开发(四十) buff效果(Potion Effect)

今天我们在1.12.2的模组中尝试实现几种特殊的buff效果

1.在开发包中新建potion包 -> potion包中新建一个BaseSimplePotion类作为我们药水效果的基类:

BaseSimplePotion.java

package com.joy187.rejoymod.potion.buff;

import com.joy187.rejoymod.potion.ModPotions;
import com.joy187.rejoymod.util.Reference;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.init.PotionTypes;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BaseSimplePotion extends Potion {
    //确定所有效果贴图的位置
    protected static final ResourceLocation resource = new ResourceLocation(Reference.Mod_ID,"textures/misc/potions.png");
    protected final int iconIndex;
    PotionType potionType=PotionTypes.MUNDANE;

//    if (!this.world.isRemote)
//    {
//        layer.getPotion().applyAttributesModifiersToEntity(this, this.getAttributeMap(), layer.getAmplifier());
//    }

    public PotionType getPotionType() {
        return potionType;
    }
                            //参数:是否为debuff buff粒子颜色 buff名称 buff对应的图标
    public BaseSimplePotion(boolean isBadEffectIn, int liquidColorIn, String name, int icon) {
        super(isBadEffectIn, liquidColorIn);
        setRegistryName(new ResourceLocation(Reference.Mod_ID, name));
        setPotionName("rejoymod.potion." + name);
        iconIndex = icon;
        ModPotions.INSTANCES.add(this);
        //setCreativeTab(tabs);
    }

    @SideOnly(Side.CLIENT)
    protected void render(int x, int y, float alpha) {
        Minecraft.getMinecraft().renderEngine.bindTexture(resource);
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder buf = tessellator.getBuffer();
        buf.begin(7, DefaultVertexFormats.POSITION_TEX);
        GlStateManager.color(1, 1, 1, alpha);

        int textureX = iconIndex % 14 * 18;
        int textureY = 198 - iconIndex / 14 * 18;

        buf.pos(x, y + 18, 0).tex(textureX * 0.00390625, (textureY + 18) * 0.00390625).endVertex();
        buf.pos(x + 18, y + 18, 0).tex((textureX + 18) * 0.00390625, (textureY
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jay_fearless

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值