版本信息
Forge版本: 2838
Minecraft版本: 1.12
Mapping 文件版本: stable_39
问题
监听RenderGameOverlayEvent时,绘制文字却没有任何反馈,但是经过测试是正常运行的。
相关代码
HudCompass用于在屏幕上绘制图形和文字
@Mod.EventBusSubscriber(modid = MidgardReborn.MODID)
public class HudCompass {
private static Minecraft mc = Minecraft.getMinecraft();
private static ScaledResolution scaled = new ScaledResolution(mc);
private static FontRenderer fontrender = mc.fontRenderer;
private final static int WIDTH = 200;
private final static int HEIGHT = 50;
private final static int OFFSETX = (scaled.getScaledWidth() - WIDTH) / 2;
private final static int OFFSETY = 10;
private static boolean S = true;
private static boolean W = true;
private static boolean N = true;
private static boolean E = true;
/** agree must be 20 - 70*/
private static float perspective = 0.5463024898F;
public HudCompass() {
MinecraftForge.EVENT_BUS.register(this);
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void onHudCompassPrint(RenderGameOverlayEvent.Text event)
{
if(event.getType() == RenderGameOverlayEvent.ElementType.ALL)
{
if(hasCompass())
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.F);
EntityPlayer player = Minecraft.getMinecraft().player;
float yaw = player.rotationYaw;
drawFont(yaw);
drawBackGround();
}
}
return;
}
private static void drawBackGround()
{
//TODO
}
private static void drawFont(float yaw)
{
reset();
float min = yaw - perspective;
float max = yaw + perspective;
if(min < -3.141592653589793F)
{
float temp = min;
min = max;
max = temp + perspective * 2;
}
if(max > -3.141592653589793F)
{
float temp = max;
max = min;
min = temp - perspective * 2;
}
EnumCompassFacing minCompassFacing = EnumCompassFacing.NORTH;
for(int agree = -180; agree < 180; agree += 90)
{
if(EnumCompassFacing.getFacingForAgree(agree).radian < min)
{
setFacingFlag(EnumCompassFacing.getFacingForAgree(agree), false);
}
else
{
minCompassFacing = EnumCompassFacing.getFacingForAgree(agree);
break;
}
}
for(int agree = 180; agree > -180; agree -= 90)
{
if(EnumCompassFacing.getFacingForAgree(agree).radian > max)
{
setFacingFlag(EnumCompassFacing.getFacingForAgree(agree), false);
}
else
{
break;
}
}
int y = OFFSETY + HEIGHT / 2;
if(Math.toDegrees(perspective * 2) < 90)
{
int x = (int) (OFFSETX + 200 * (minCompassFacing.radian - min / perspective * 2));
fontrender.drawString(minCompassFacing.getInitials(), x, y, 14737632);
}
}
private static void reset()
{
W = true;
E = true;
S = true;
W = true;
}
private static void setFacingFlag(EnumCompassFacing facing, boolean active)
{
if(facing == EnumCompassFacing.NORTH)
{
N = active;
}
else if(facing == EnumCompassFacing.EAST)
{
E = active;
}
else if(facing == EnumCompassFacing.SOUTH)
{
S = active;
}
else
{
W = active;
}
}
private static boolean hasCompass()
{
//TODO
return true;
}
public static enum EnumCompassFacing
{
NORTH(3.141592653589793F),
EAST(1.570796326794897F),
SOUTH(0.0F),
WEST(-1.570796326794897F);
public float radian;
private EnumCompassFacing(float radian) {
this.radian = radian;
}
/**
* @param agree agree value <b>-180</b> between <b>180</b>
* <br> enter the wrong parameter <b>WILL RETURN NULL</b>
* @return
* -180 - {@link EnumCompassFacing#NORTH} <br>
* -90 - {@link EnumCompassFacing#EAST} <br>
* 0 - {@link EnumCompassFacing#SORTH} <br>
* 90 - {@link EnumCompassFacing#EAST} <br>
* 180 - {@link EnumCompassFacing#NORTH} <br>
*/
@Nullable
public static EnumCompassFacing getFacingForAgree(int agree)
{
switch(agree)
{
case 0:
return SOUTH;
case 90:
return EAST;
case -90:
return WEST;
case 180:
case -180:
return NORTH;
default:
return null;
}
}
public String getInitials()
{
switch(this)
{
case NORTH:
return "N";
case EAST:
return "E";
case SOUTH:
return "S";
case WEST:
return "W";
default:
return "";
}
}
public float getMiniMumCritical()
{
return this.radian - perspective;
}
public float getMaxMumCritical()
{
return this.radian + perspective;
}
}
}
查到的资料
去论坛和查阅教程时都是使用FontRenderer#drawString来绘制文字,甚至也尝试将Post事件改成Text,但是感觉没有任何变化