今天我们在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

最低0.47元/天 解锁文章
2056

被折叠的 条评论
为什么被折叠?



