diff --git a/src/main/java/cn/mcxkly/classicandsimplestatusbars/ClassicAndSimpleStatusBars.java b/src/main/java/cn/mcxkly/classicandsimplestatusbars/ClassicAndSimpleStatusBars.java index 33d99c7..ed16f7d 100644 --- a/src/main/java/cn/mcxkly/classicandsimplestatusbars/ClassicAndSimpleStatusBars.java +++ b/src/main/java/cn/mcxkly/classicandsimplestatusbars/ClassicAndSimpleStatusBars.java @@ -1,6 +1,8 @@ package cn.mcxkly.classicandsimplestatusbars; +import cn.mcxkly.classicandsimplestatusbars.overlays.FoodLevel; import cn.mcxkly.classicandsimplestatusbars.overlays.ThirstWasTaken; +import cn.mcxkly.classicandsimplestatusbars.overlays.ThirstWasTakenUse; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod; @@ -14,8 +16,10 @@ public ClassicAndSimpleStatusBars() { // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); -// if (ModList.get().isLoaded("thirst")) { -// MinecraftForge.EVENT_BUS.register(new ThirstWasTaken()); -// } + if (ModList.get().isLoaded("thirst")) { + //MinecraftForge.EVENT_BUS.register(new ThirstWasTaken()); + ThirstWasTakenUse.StopConflictRenderingIDEA(false); + FoodLevel.StopConflictRenderingIDEA(false); + } } } diff --git a/src/main/java/cn/mcxkly/classicandsimplestatusbars/events/OverlayRegisteringThirstLevel.java b/src/main/java/cn/mcxkly/classicandsimplestatusbars/events/OverlayRegisteringThirstLevel.java index 5783d58..24c2e08 100644 --- a/src/main/java/cn/mcxkly/classicandsimplestatusbars/events/OverlayRegisteringThirstLevel.java +++ b/src/main/java/cn/mcxkly/classicandsimplestatusbars/events/OverlayRegisteringThirstLevel.java @@ -14,6 +14,6 @@ public class OverlayRegisteringThirstLevel { @SubscribeEvent public static void registerthirst(RegisterGuiOverlaysEvent event) { - // event.registerBelow(chatOverlayLocation, "thirst_level", Overlays.thirstlevel); + event.registerBelow(chatOverlayLocation, "thirst_level", Overlays.thirstlevel); } } \ No newline at end of file diff --git a/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/FoodLevel.java b/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/FoodLevel.java index 1b80987..d1ef5ef 100644 --- a/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/FoodLevel.java +++ b/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/FoodLevel.java @@ -31,6 +31,8 @@ public class FoodLevel implements IGuiOverlay { private static final ResourceLocation guiIconsLocation = new ResourceLocation("minecraft", "textures/gui/icons.png"); private float intermediateFood = 0; private float intermediateFoodSaturation = 0; + public static boolean StopConflictRendering = true; // 支持口渴 + public static void StopConflictRenderingIDEA(boolean is){StopConflictRendering = is;}; @Override public void render(ForgeGui gui, GuiGraphics guiGraphics, float partialTick, int width, int height) { if (gui.shouldDrawSurvivalElements()) { @@ -41,7 +43,7 @@ public void render(ForgeGui gui, GuiGraphics guiGraphics, float partialTick, int int x = width / 2 + 11; int y = height - 39; y += 4; - y -= 70; //test + //y -= 70; // test updateBarTextures(player); renderFoodBar(font,guiGraphics, partialTick, x, y, player); //Sntext = renderMountValue(player); @@ -105,15 +107,16 @@ private void renderFoodValue(Font font, GuiGraphics guiGraphics, int x, int y, P if (player.getAirSupply() < 300) { // max=300 int siz = player.getAirSupply() / 3; String text; - siz = siz > 0 ? siz : 0;//防止负数 + siz = Math.max(siz, 0); //防止负数 text = String.valueOf(siz); + int Y2 = y; + if (!StopConflictRendering) Y2 -= 10; // 如果口渴存在,在渲染时高度 + 10 + guiGraphics.drawString(font, "%", x + 70 - font.width("%"), Y2 - 9, 0x1E90FF, false); - guiGraphics.drawString(font, "%", x + 80 - font.width("%"), y - 9, 0x1E90FF, false); - - guiGraphics.drawString(font, text, x + 80 - font.width("99%"), y - 9, 0x1E90FF, false); + guiGraphics.drawString(font, text, x + 70 - font.width("99%"), Y2 - 9, 0x1E90FF, false); guiGraphics.blit(guiIconsLocation, - x + 80 - font.width("99%") - 10, y - 10, - 16, 19, + x + 70, Y2 - 10, + 16, 18, 9, 9, 256, 256); // 气泡图标 } diff --git a/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/Overlays.java b/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/Overlays.java index 62c8f2e..bcdaf6f 100644 --- a/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/Overlays.java +++ b/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/Overlays.java @@ -6,6 +6,6 @@ public class Overlays { public static HealthBar healthBar = new HealthBar(); public static FoodLevel foodlevel = new FoodLevel(); - //public static ThirstWasTakenUse thirstlevel = new ThirstWasTakenUse(); + public static ThirstWasTakenUse thirstlevel = new ThirstWasTakenUse(); } diff --git a/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/ThirstWasTakenUse.java b/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/ThirstWasTakenUse.java index 916b290..245f92c 100644 --- a/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/ThirstWasTakenUse.java +++ b/src/main/java/cn/mcxkly/classicandsimplestatusbars/overlays/ThirstWasTakenUse.java @@ -15,46 +15,50 @@ public class ThirstWasTakenUse implements IGuiOverlay { private static final Minecraft mc = Minecraft.getInstance(); + public static boolean StopConflictRendering = true; + public static void StopConflictRenderingIDEA(boolean is){StopConflictRendering = is;}; public static IThirst PLAYER_THIRST = null; - public static ResourceLocation THIRST_ICONS = new ResourceLocation(Thirst.ID, "textures/gui/thirst_icons.png"); + public static final ResourceLocation THIRST_ICONS = new ResourceLocation(Thirst.ID, "textures/gui/thirst_icons.png"); public static final ResourceLocation MC_ICONS = new ResourceLocation("minecraft", "textures/gui/icons.png"); @Override public void render(ForgeGui gui, GuiGraphics guiGraphics, float partialTick, int width, int height) { - Player player = null; - int y = 0; - int x = 0; - Font font = null; - if (gui.shouldDrawSurvivalElements()) { - font = gui.getFont(); - - player = (Player) Minecraft.getInstance().cameraEntity; + if (gui.shouldDrawSurvivalElements() && !StopConflictRendering) { + Font font = gui.getFont(); + + Player player = (Player) Minecraft.getInstance().cameraEntity; if (player == null) return; - x = width / 2 + 11; - y = height - 39; + int x = width / 2 + 11; + int y = height - 39; y += 4; - } - renderThirstLevelBar(font, guiGraphics, partialTick, x, y, player); + renderThirstLevelBar(font, guiGraphics, partialTick, x, y, player); + } } - private void renderThirstLevelBar(Font font, GuiGraphics guiGraphics, float partialTick, int x, int y, Player player) { // guiGraphics.blit(emptyHealthBarLocation, // x, y, // 0, 0, // 80, 5, // 80, 5); - String text; - if (PLAYER_THIRST == null || mc.player.tickCount % 40 == 0) { - assert mc.player != null; - PLAYER_THIRST = (IThirst) mc.player.getCapability(ModCapabilities.PLAYER_THIRST).orElse(null); - } - text = PLAYER_THIRST.getThirst() + " | " + PLAYER_THIRST.getQuenched(); - guiGraphics.drawString(font, text, x, y - 19, 0xF4A460, false); - guiGraphics.blit(THIRST_ICONS, x, y, 0.0F, 0.0F, 9, 9, 25, 9); - guiGraphics.blit(THIRST_ICONS, x, y, 8.0F, 0.0F, 9, 9, 25, 9); + PLAYER_THIRST = player.getCapability(ModCapabilities.PLAYER_THIRST).orElse(null); + int Thirst = PLAYER_THIRST.getThirst(); + int Quenched = PLAYER_THIRST.getQuenched(); + + guiGraphics.blit(THIRST_ICONS, + x + 70, y - 10, + 16.0F, 0.0F, + 9, 9, + 25, 9); + if (Quenched > 0){ // 如果Quenched大于0渲染. + int x2 = x + 70 - font.width(Quenched + "+") - font.width(String.valueOf(Thirst)); // 计算长度 + // guiGraphics.blit(THIRST_ICONS, x, y, 0.0F, 0.0F, 9, 9, 25, 9); + guiGraphics.drawString(font, Quenched + "+", x2, y - 9, 0x48D1CC, false); + } + font.width("0.3"); + guiGraphics.drawString(font, String.valueOf(Thirst), x + 70 - font.width(String.valueOf(Thirst)), y - 9, 0x4876FF, false); } }