Skip to content

Commit f4340a2

Browse files
authored
1.21.11 (#94)
* 25w45a * Update LocatorBarMixin.java * Nautilus dash bar fix * Default to dash bar for unknown mobs * Rename methods too * Improved but default-disabled mount jump/dash text * Bump deps * Breath of the Nautilus * Fixes Fixed diamond and netherite horse/nautilus armor being considered the same.
1 parent 23ae41e commit f4340a2

13 files changed

Lines changed: 137 additions & 91 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The mod only uses client-side data, so it is never needed on a server. There are
6666
| Totem of Undying | | | +ቶ1 | +tu1 | Opt-in, shows the amount of Totem of Undyings in your inventory; crossed out when not held in main/offhand. |
6767
| Fire resistance | | | -~🔥1×~ | -~bu1×~ | Number is a rough damage multiplier (1× - burning, 2× - in fire, 3× - in soul fire, 4× - in lava), only shown if you are on fire |
6868
| Water Breathing, Conduit Power | Blue || -~⭘1~ | -~ai1~ | The bar is only shown if you got the effect after losing air, text is only shown if you are in water |
69+
| Breath of the Nautilus | Blue || -⭘1⏸️ | -ap1 | The bar is only shown if you got the effect after losing air, text is only shown if you are in water, text is crossed if combined with water breathing-like effect. |
6970
| Held food restored hunger: exact/less | Green || _→1_ | _→1_ | Overlaid on hunger bar; number is the resulting hunger (like AppleSkin) |
7071
| Held food restored hunger: wasted | Orange || _→-1_ | _→-1_ | Overlaid on hunger bar; number is the waste of hunger (how much more than needed) |
7172
| Saturation | Orange || | Below OneBar | Opt-in |

gradle.properties

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ org.gradle.configuration-cache=false
77

88
# Fabric Properties
99
# check these on https://fabricmc.net/develop/
10-
minecraft_version=1.21.10
11-
yarn_mappings=1.21.10+build.2
12-
loader_version=0.17.3
10+
minecraft_version=1.21.11
11+
loader_version=0.18.2
1312
loom_version=1.13-SNAPSHOT
1413

1514
# Mod Properties
16-
mod_version = 5.1.3
15+
mod_version = 5.2.0
1716
maven_group = io.github.madis0
1817
archives_base_name = onebar
1918

2019
# Dependencies
21-
fabric_api_version=0.138.0+1.21.10
22-
modmenu_version=16.0.0-rc.1
23-
cloth_config_version=20.0.149
20+
fabric_api_version=0.139.5+1.21.11
21+
modmenu_version=17.0.0-alpha.1
22+
cloth_config_version=21.11.151
2423
exordium_version=1.2.1-1.20.2

src/main/java/io/github/madis0/Calculations.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,39 @@ public static String emojiOrText(String emojiPhrase, String textPhrase, boolean
9595

9696
/**
9797
* Converts horse's jump strength to jump height, may not be 100% accurate
98-
* <a href="https://github.com/d4rkm0nkey/HorseStatsVanilla/blob/main/src/main/java/monkey/lumpy/horse/stats/vanilla/util/Converter.java">Source</a>
98+
* <a href="https://github.com/d4rkm0nkey/HorseStatsVanilla/blob/main/src/client/java/monkey/lumpy/horse/stats/vanilla/util/Converter.java">Source</a>
9999
* @param strength Horse jump strength
100100
* @return Jump height in blocks
101101
*/
102-
public static double horseJumpStrengthToJumpHeight(double strength) {
103-
return -0.1817584952 * strength * strength * strength + 3.689713992 * strength * strength + 2.128599134 * strength - 0.343930367;
102+
public static double getJumpHeight(double strength) {
103+
double height = 0;
104+
double velocity = strength;
105+
while(velocity > 0) {
106+
height += velocity;
107+
velocity = (velocity - .08) * .98 * .98;
108+
}
109+
return height;
110+
}
111+
112+
public static double getDashDistance(float strength) {
113+
// Minecraft gravity constant (approximately)
114+
final double gravity = 0.08; // Blocks/tick^2
115+
final double jumpVelocityOneBlock = Math.sqrt(2 * gravity * 1); // Velocity needed to reach 1 block high
116+
117+
// Default values for movement speed and velocity multiplier
118+
final double defaultMovementSpeed = 0.12; // Adjusted for the camel's movement speed
119+
final double defaultVelocityMultiplier = 1.0; // Neutral velocity multiplier
120+
121+
// Horizontal velocity calculation with adjusted factor
122+
double horizontalVelocity = 11.1111F * strength * defaultMovementSpeed * defaultVelocityMultiplier;
123+
124+
// Time in the air (based on jumping 1 block high)
125+
double initialVerticalVelocity = jumpVelocityOneBlock * strength;
126+
double timeUp = initialVerticalVelocity / gravity; // Time to reach the peak
127+
double totalTimeInAir = timeUp * 2;
128+
129+
// Horizontal distance = horizontal velocity * total time in air
130+
return horizontalVelocity * totalTimeInAir;
104131
}
105132

106133
/**

src/main/java/io/github/madis0/ClientProperties.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public class ClientProperties {
2323
public int xpStartH;
2424
public final int xpEndH;
2525

26-
public final int horseJumpStartW;
27-
public final int horseJumpEndW;
28-
public final int horseJumpStartH;
29-
public final int horseJumpEndH;
30-
31-
public final int camelJumpStartW;
32-
public final int camelJumpEndW;
33-
public final int camelJumpStartH;
34-
public final int camelJumpEndH;
26+
public final int jumpStartW;
27+
public final int jumpEndW;
28+
public final int jumpStartH;
29+
public final int jumpEndH;
30+
31+
public final int dashStartW;
32+
public final int dashEndW;
33+
public final int dashStartH;
34+
public final int dashEndH;
3535
public final int mountStartH;
3636
public final int mountEndH;
3737

@@ -106,15 +106,15 @@ else if(hasHotbarLocatorBar){
106106
xpEndW = xpStartW + 18;
107107
xpEndH = xpStartH + 1;
108108

109-
horseJumpStartW = (scaledWidth / 2) - 7;
110-
horseJumpStartH = (scaledHeight / 2) + 15;
111-
horseJumpEndW = horseJumpStartW + 13;
112-
horseJumpEndH = horseJumpStartH + 50;
109+
jumpStartW = (scaledWidth / 2) - 7;
110+
jumpStartH = (scaledHeight / 2) + 15;
111+
jumpEndW = jumpStartW + 13;
112+
jumpEndH = jumpStartH + 50;
113113

114-
camelJumpStartW = baseStartW + 65;
115-
camelJumpEndW = camelJumpStartW + 50;
116-
camelJumpStartH = horseJumpStartH;
117-
camelJumpEndH = camelJumpStartH + 7;
114+
dashStartW = baseStartW + 65;
115+
dashEndW = dashStartW + 50;
116+
dashStartH = jumpStartH;
117+
dashEndH = dashStartH + 7;
118118

119119
mountStartH = baseStartH - 12;
120120
mountEndH = mountStartH + 9;
@@ -148,10 +148,10 @@ public int baseRelativeStartW(float value, float total){
148148
return baseRelativeStartW(Calculations.getPreciseInt(value), Calculations.getPreciseInt(total));
149149
}
150150

151-
public int camelRelativeEndW(int value, int total){
152-
return Calculations.relativeW(camelJumpStartW, camelJumpEndW, value, total);
151+
public int dashRelativeEndW(int value, int total){
152+
return Calculations.relativeW(dashStartW, dashEndW, value, total);
153153
}
154-
public int camelRelativeEndW(long value, long total){
155-
return camelRelativeEndW(Calculations.getPreciseInt(value), Calculations.getPreciseInt(total));
154+
public int dashRelativeEndW(long value, long total){
155+
return dashRelativeEndW(Calculations.getPreciseInt(value), Calculations.getPreciseInt(total));
156156
}
157157
}

src/main/java/io/github/madis0/ModConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static class Entity {
122122
@ConfigEntry.Gui.Tooltip
123123
public boolean showMountJump = true;
124124
@ConfigEntry.Gui.Tooltip
125-
public boolean showMountJumpText = true;
125+
public boolean showMountJumpText = false;
126126
@ConfigEntry.ColorPicker(allowAlpha = true)
127127
public int jumpColor = 0xFF795548;
128128
@ConfigEntry.Gui.Tooltip

src/main/java/io/github/madis0/ModMenuIntegration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ public class ModMenuIntegration implements ModMenuApi {
99
public ConfigScreenFactory<?> getModConfigScreenFactory() {
1010
return parent -> AutoConfig.getConfigScreen(ModConfig.class, parent).get();
1111
}
12-
}
12+
}

src/main/java/io/github/madis0/OneBar.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import net.minecraft.client.KeyMapping;
1010
import net.minecraft.client.Minecraft;
1111
import net.minecraft.network.chat.Component;
12-
import net.minecraft.resources.ResourceLocation;
12+
import net.minecraft.resources.Identifier;
1313

1414
public class OneBar implements ClientModInitializer {
1515
static KeyMapping.Category ONEBAR_MAIN;
@@ -25,7 +25,7 @@ public void onInitializeClient() {
2525

2626
ModConfig config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
2727

28-
ONEBAR_MAIN = KeyMapping.Category.register(ResourceLocation.fromNamespaceAndPath("onebar", "main"));
28+
ONEBAR_MAIN = KeyMapping.Category.register(Identifier.fromNamespaceAndPath("onebar", "main"));
2929

3030
KeyMapping showOneBar = registerKeybind("text.autoconfig.onebar.option.showOneBar");
3131
KeyMapping healthEstimates = registerKeybind("text.autoconfig.onebar.option.healthEstimates");

src/main/java/io/github/madis0/OneBarElements.java

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.minecraft.world.entity.ai.attributes.Attribute;
1717
import net.minecraft.world.entity.ai.attributes.Attributes;
1818
import net.minecraft.world.entity.animal.camel.Camel;
19+
import net.minecraft.world.entity.animal.equine.AbstractHorse;
1920
import net.minecraft.world.entity.player.Player;
2021
import net.minecraft.world.item.ItemStack;
2122
import net.minecraft.world.item.Items;
@@ -351,10 +352,14 @@ private void barText(){
351352

352353
if(playerProperties.isWardenNear && config.badThings.showWarden)
353354
value += minus + Calculations.emojiOrText("text.onebar.wardenEmoji","text.onebar.warden",false, Calculations.makeFraction(playerProperties.wardenDanger, false));
354-
if (playerProperties.isUnderwater && !playerProperties.hasWaterBreathing)
355+
if (playerProperties.isUnderwater && !playerProperties.hasWaterBreathing && !playerProperties.hasWaterPause)
355356
value += minus + Calculations.emojiOrText("text.onebar.airEmoji", "text.onebar.air", false, Calculations.makeFraction(playerProperties.air, false));
356-
if (playerProperties.isUnderwater && playerProperties.hasWaterBreathing)
357+
if (playerProperties.isUnderwater && playerProperties.hasWaterBreathing && !playerProperties.hasWaterPause)
357358
value += minus + para + "m" + Calculations.emojiOrText("text.onebar.airEmoji","text.onebar.air", false, Calculations.makeFraction(playerProperties.air, false)) + para + "r";
359+
if (playerProperties.isUnderwater && !playerProperties.hasWaterBreathing && playerProperties.hasWaterPause)
360+
value += minus + Calculations.emojiOrText("text.onebar.airPauseEmoji","text.onebar.airPause", false, Calculations.makeFraction(playerProperties.air, false));
361+
if (playerProperties.isUnderwater && playerProperties.hasWaterBreathing && playerProperties.hasWaterPause)
362+
value += minus + para + "m" + Calculations.emojiOrText("text.onebar.airPauseEmoji","text.onebar.airPause", false, Calculations.makeFraction(playerProperties.air, false)) + para + "r";
358363
if (playerProperties.isFreezing)
359364
value += minus + Calculations.emojiOrText("text.onebar.freezeEmoji", "text.onebar.freeze", false, Calculations.makeFraction(playerProperties.freeze, false));
360365
if (playerProperties.isBurning && !playerProperties.hasFireResistance && config.badThings.showFire)
@@ -475,65 +480,74 @@ public void mountJumpBar() {
475480
var entity = client.player.getControlledVehicle();
476481
if (entity == null) return;
477482

478-
if (entity instanceof Camel) {
479-
camelJumpBar();
480-
} else {
481-
horseJumpBar(); // Horse or modded entity
483+
if (entity instanceof AbstractHorse && !(entity instanceof Camel)) {
484+
jumpBar();
485+
} else { // Camel, Nautilus, modded mobs
486+
dashBar();
482487
}
483488
}
484489

485-
public void horseJumpBar(){
490+
public void jumpBar(){
486491
if (client.player == null || client.player.jumpableVehicle() == null) return;
487492

488493
int barHeight = Calculations.getPreciseInt(1.0F);
489494
int jumpHeight = Calculations.getPreciseInt(client.player.getJumpRidingScale());
490495

491496
double heightInBlocks = Math.max(0, client.player.getJumpRidingScale() *
492-
Calculations.horseJumpStrengthToJumpHeight(client.player.getJumpRidingScale()));
497+
Calculations.getJumpHeight(client.player.getJumpRidingScale()));
493498

494499
String roundedHeightInBlocks = Calculations.getSubscriptNumber(Double.parseDouble(String.format(Locale.US, "%,.1f",(heightInBlocks))));
495500

496-
int relativeStartH = Calculations.relativeW(clientProperties.horseJumpEndH, clientProperties.horseJumpStartH, jumpHeight, barHeight);
497-
renderBar(clientProperties.horseJumpStartW, clientProperties.horseJumpStartH, clientProperties.horseJumpEndW, clientProperties.horseJumpEndH, config.backgroundColor);
498-
renderBar(clientProperties.horseJumpStartW, relativeStartH, clientProperties.horseJumpEndW, clientProperties.horseJumpEndH, config.entity.jumpColor);
501+
int relativeStartH = Calculations.relativeW(clientProperties.jumpEndH, clientProperties.jumpStartH, jumpHeight, barHeight);
502+
renderBar(clientProperties.jumpStartW, clientProperties.jumpStartH, clientProperties.jumpEndW, clientProperties.jumpEndH, config.backgroundColor);
503+
renderBar(clientProperties.jumpStartW, relativeStartH, clientProperties.jumpEndW, clientProperties.jumpEndH, config.entity.jumpColor);
499504

500-
int textX = clientProperties.horseJumpEndW - client.font.width(roundedHeightInBlocks);
501-
int textY = clientProperties.horseJumpEndH - 10;
505+
int textX = clientProperties.jumpEndW - client.font.width(roundedHeightInBlocks);
506+
int textY = clientProperties.jumpEndH - 10;
502507

503508
if(config.textSettings.showText && config.entity.showMountJumpText)
504509
drawContext.drawString(textRenderer, roundedHeightInBlocks, textX, textY, config.textSettings.textColor, false);
505510
}
506511

507-
public void camelJumpBar(){
512+
public void dashBar(){
508513
if (client.player == null || client.player.jumpableVehicle() == null) return;
509514

510515
int jumpStrength = Calculations.getPreciseInt(Math.max(client.player.getJumpRidingScale(), 0)); //TODO: strength can be negative???
511516
int maxStrength = Calculations.getPreciseInt(1.0F);
512-
int cooldown = client.player.jumpableVehicle().getJumpCooldown();
517+
int cooldown = Objects.requireNonNull(client.player.jumpableVehicle()).getJumpCooldown();
513518
int maxCooldown = 50;
514519
int cooldownVisible = cooldown / 20;
515520

516-
int relativeEndW = clientProperties.camelRelativeEndW(jumpStrength, maxStrength);
517-
int relativeEndWCooldown = clientProperties.camelRelativeEndW(cooldown, maxCooldown);
521+
double distanceInBlocks = Math.max(0, Calculations.getDashDistance(client.player.getJumpRidingScale()));
522+
523+
int relativeEndW = clientProperties.dashRelativeEndW(jumpStrength, maxStrength);
524+
int relativeEndWCooldown = clientProperties.dashRelativeEndW(cooldown, maxCooldown);
518525

519526
if(relativeEndWCooldown > relativeEndW){
520-
camelCooldownBar(relativeEndWCooldown, cooldownVisible);
527+
dashCooldownBar(relativeEndWCooldown, cooldownVisible);
521528
}
522529
else {
523-
renderBar(clientProperties.camelJumpStartW, clientProperties.camelJumpStartH, clientProperties.camelJumpEndW, clientProperties.camelJumpEndH, config.backgroundColor);
524-
renderBar(clientProperties.camelJumpStartW, clientProperties.camelJumpStartH, relativeEndW, clientProperties.camelJumpEndH, config.entity.jumpColor);
530+
renderBar(clientProperties.dashStartW, clientProperties.dashStartH, clientProperties.dashEndW, clientProperties.dashEndH, config.backgroundColor);
531+
renderBar(clientProperties.dashStartW, clientProperties.dashStartH, relativeEndW, clientProperties.dashEndH, config.entity.jumpColor);
532+
533+
if(config.textSettings.showText && config.entity.showMountJumpText){
534+
String roundedDistanceInBlocks = Calculations.getSubscriptNumber(Double.parseDouble(String.format(Locale.US, "%,.1f",(distanceInBlocks))));
535+
int textX = clientProperties.dashEndW - client.font.width(roundedDistanceInBlocks);
536+
int textY = clientProperties.dashEndH - 9;
537+
drawContext.drawString(textRenderer, roundedDistanceInBlocks, textX, textY, config.textSettings.textColor, false);
538+
}
525539
}
526540
}
527541

528-
private void camelCooldownBar(int relativeEndW, int cooldownTimer){
542+
private void dashCooldownBar(int relativeEndW, int cooldownTimer){
529543
if(config.entity.showMountCooldown){
530-
renderBar(clientProperties.camelJumpStartW, clientProperties.camelJumpStartH, clientProperties.camelJumpEndW, clientProperties.camelJumpEndH, config.backgroundColor);
531-
renderBar(clientProperties.camelJumpStartW, clientProperties.camelJumpStartH, relativeEndW, clientProperties.camelJumpEndH, config.entity.cooldownColor);
544+
renderBar(clientProperties.dashStartW, clientProperties.dashStartH, clientProperties.dashEndW, clientProperties.dashEndH, config.backgroundColor);
545+
renderBar(clientProperties.dashStartW, clientProperties.dashStartH, relativeEndW, clientProperties.dashEndH, config.entity.cooldownColor);
532546

533547
if(config.textSettings.showText && config.entity.showMountCooldownText){
534548
String text = Calculations.getSubscriptNumber(-1 - cooldownTimer);
535-
int textX = clientProperties.camelJumpEndW - client.font.width(text);
536-
int textY = clientProperties.camelJumpEndH - 9;
549+
int textX = clientProperties.dashEndW - client.font.width(text);
550+
int textY = clientProperties.dashEndH - 9;
537551
drawContext.drawString(textRenderer, text, textX, textY, config.textSettings.textColor, false);
538552
}
539553
}
@@ -558,16 +572,16 @@ public void mountBar(LivingEntity mountEntity){
558572
float mountRawHealth = mountEntity.getHealth();
559573
float mountMaxHealth = mountEntity.getMaxHealth();
560574
int health = (int) Math.ceil(mountRawHealth);
561-
int horseArmor = mountEntity.getArmorValue();
562-
int horseMaxArmor = getProtectionFromArmor(new ItemStack((Items.DIAMOND_HORSE_ARMOR)));
575+
int mountArmor = mountEntity.getArmorValue();
576+
int mountMaxArmor = getProtectionFromArmor(new ItemStack((Items.NETHERITE_HORSE_ARMOR)));
563577

564578
String value = Calculations.emojiOrText("text.onebar.mountHealthEmoji","text.onebar.mountHealth", true, config.textSettings.rawHealth ? (Math.round(mountRawHealth * 100.0) / 100.0) : Calculations.makeFraction(health, false));
565579
int textX = clientProperties.baseEndW - client.font.width(value);
566580
int textY = clientProperties.mountStartH + 1;
567581

568582
renderBar(clientProperties.baseStartW, clientProperties.mountStartH, clientProperties.baseEndW, clientProperties.mountEndH, config.backgroundColor);
569583
renderBar(clientProperties.baseStartW, clientProperties.mountStartH, clientProperties.baseRelativeEndW(Calculations.getPreciseInt(mountRawHealth), Calculations.getPreciseInt(mountMaxHealth)), clientProperties.mountEndH, config.entity.healthColor);
570-
if(config.armor.showArmorBar) renderBar(clientProperties.baseStartW, clientProperties.mountStartH - 1, clientProperties.baseRelativeEndW(horseArmor, horseMaxArmor), clientProperties.mountStartH, config.armor.armorColor);
584+
if(config.armor.showArmorBar) renderBar(clientProperties.baseStartW, clientProperties.mountStartH - 1, clientProperties.baseRelativeEndW(mountArmor, mountMaxArmor), clientProperties.mountStartH, config.armor.armorColor);
571585
if(config.textSettings.showText) drawContext.drawString(textRenderer, value, textX, textY, config.textSettings.textColor, false);
572586

573587
if(mountEntity instanceof Camel){
@@ -576,7 +590,7 @@ public void mountBar(LivingEntity mountEntity){
576590
int standingUpTimerVisible = Math.round((standingUpMax - standingUpTimer) / (float)20);
577591

578592
if(((Camel)mountEntity).isInPoseTransition()){
579-
camelCooldownBar(clientProperties.camelRelativeEndW(standingUpMax - standingUpTimer, standingUpMax), standingUpTimerVisible);
593+
dashCooldownBar(clientProperties.dashRelativeEndW(standingUpMax - standingUpTimer, standingUpMax), standingUpTimerVisible);
580594
}
581595
}
582596

0 commit comments

Comments
 (0)