Skip to content

Commit

Permalink
Add compatibility with Thirst and Toughasnails mods
Browse files Browse the repository at this point in the history
Now it's done
  • Loading branch information
Xing-C committed Sep 13, 2023
1 parent 5ee4731 commit ab54c10
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
Expand Down Expand Up @@ -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); // 气泡图标
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit ab54c10

Please sign in to comment.