你使用的IDE:IntelliJ IDEA
你使用的IDE版本: 2019.3.3
Forge版本: 2876
Minecraft版本: 1.12.2
错误情况简述
通过mc.ingameGUI.drawTexturedModalRect 加载的png图片会炸 会自动填缺口(透明像素)
图片
相关代码
package cc.kunss.basics.hud;
import cc.kunss.basics.BasicsLibrary;
import cc.kunss.basics.message.BasicsMessage;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
public class HealthHud extends AbstractHud{
public ResourceLocation hud = new ResourceLocation(BasicsLibrary.MOD_ID, "textures/gui/bar.png");
private double health = 20;
private double maxHealth = 20;
@Override
public void handle(RenderGameOverlayEvent e, Minecraft mc) {
if (e.getType().equals(RenderGameOverlayEvent.ElementType.ALL) && e.isCancelable()) {
mc.getTextureManager().bindTexture(hud);
int width = (int) ((health / maxHealth) * 200);
mc.ingameGUI.drawTexturedModalRect(5, 5, 0, 0, 168, 55);
}
if ((e.getType().equals(RenderGameOverlayEvent.ElementType.EXPERIENCE) || e.getType().equals(RenderGameOverlayEvent.ElementType.FOOD) || e.getType().equals(RenderGameOverlayEvent.ElementType.HEALTH) || e.getType().equals(RenderGameOverlayEvent.ElementType.ARMOR)) && e.isCancelable()) {
e.setCanceled(true);
}
}
@Override
public void update(BasicsMessage basicsMessage) {
animation(this,new String[]{"health"},new double[]{health},new double[]{basicsMessage.getInt("health")},basicsMessage.getDouble("time"));
this.maxHealth = basicsMessage.getInt("maxHealth");
}
}