Skip to content

Commit

Permalink
Merge pull request #2 from IzzyDotExe/unstable-position-fix
Browse files Browse the repository at this point in the history
Fix Y axis lock
  • Loading branch information
IzzyDotExe authored Jun 30, 2023
2 parents 1648e48 + 2528678 commit f26da4b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 70 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.21

# Mod Properties
mod_version = 0.1
mod_version = 0.2
maven_group = ca.blutopia
archives_base_name = armorskin

Expand Down
169 changes: 100 additions & 69 deletions src/main/java/ca/blutopia/armorskin/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
Expand Down Expand Up @@ -33,57 +34,68 @@ public abstract class InGameHudMixin {

@Shadow @Final private static ResourceLocation GUI_ICONS_LOCATION;

private Dictionary<ArmorMaterial, Number> defenseDict = new Hashtable<>();
private ArmorMaterial current = null;

@Redirect(method = "renderPlayerHealth", at=@At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blit(Lnet/minecraft/resources/ResourceLocation;IIIIII)V", ordinal = 0))
private void RedirectHalfArmor(GuiGraphics instance, ResourceLocation resourceLocation, int x, int y, int u, int v, int width, int height) {

if (current == null || defenseDict.get(current).intValue() <= 0)
current = getHighestNumericValue(defenseDict);

var Vvalue = switch (current != null? current.getName().toLowerCase() : "null") {
case "diamond" -> 9;
case "leather" -> 0;
case "netherite" -> 18;
case "gold" -> 27;
case "chainmail" -> 36;
default -> 45;
};

instance.blit(resourceLocation, x, y, 238, Vvalue, width, height);
if (current != null)
defenseDict.put(current, defenseDict.get(current).intValue() - 2);
}
@Redirect(method = "renderPlayerHealth", at=@At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blit(Lnet/minecraft/resources/ResourceLocation;IIIIII)V", ordinal = 1))
private void RedirectFullArmor(GuiGraphics instance, ResourceLocation resourceLocation, int x, int y, int u, int v, int width, int height) {

if (current == null || defenseDict.get(current).intValue() <= 0)
current = getHighestNumericValue(defenseDict);

var Vvalue = switch (current != null? current.getName().toLowerCase() : "null") {
case "diamond" -> 9;
case "leather" -> 0;
case "netherite" -> 18;
case "gold" -> 27;
case "chainmail" -> 36;
default -> 45;
};

instance.blit(resourceLocation, x, y, 229, Vvalue, width, height);
if (current != null)
defenseDict.put(current, defenseDict.get(current).intValue() - 1);
}
@Redirect(method = "renderPlayerHealth", at=@At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blit(Lnet/minecraft/resources/ResourceLocation;IIIIII)V", ordinal = 2))
private void RedirectEmptyArmor(GuiGraphics instance, ResourceLocation resourceLocation, int x, int y, int u, int v, int width, int height) {

if (current == null || defenseDict.get(current).intValue() <= 0)
current = getHighestNumericValue(defenseDict);

var Vvalue = switch (current != null? current.getName().toLowerCase() : "null") {
case "diamond" -> 9;
case "leather" -> 0;
case "netherite" -> 18;
case "gold" -> 27;
case "chainmail" -> 36;
default -> 45;
};

instance.blit(resourceLocation, x, y, 220, Vvalue, width, height);
}

@Inject(method = "renderPlayerHealth", at=@At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;push(Ljava/lang/String;)V", ordinal = 0))
private void RenderArmorBarInject(GuiGraphics guiGraphics, CallbackInfo ci) {
var player = getCameraPlayer();
int i = Mth.ceil(player.getHealth());
int j = displayHealth;
float f = Math.max((float)player.getAttributeValue(Attributes.MAX_HEALTH), (float)Math.max(j, i));
int p = Mth.ceil(player.getAbsorptionAmount());
int q = Mth.ceil((f + (float)p) / 2.0f / 10.0f);
int r = Math.max(10 - (q - 2), 3);
int o = screenHeight - 39;
int s = o - (q - 1) * r - 10;
int x = screenWidth / 2 - 91;

renderArmorBar(guiGraphics, player, x, s);
}

public <K> K getHighestNumericValue(Dictionary<K, Number> dict) {
K highVal = null;
Number prevVal = 0;
for (Iterator<K> it = dict.keys().asIterator(); it.hasNext(); ) {
K key = it.next();

if (dict.get(key).doubleValue() > prevVal.doubleValue()) {
highVal = key;
prevVal = dict.get(key);
}
}

return highVal;
}

public void renderArmorBar(GuiGraphics graphics, Player playerEntity, int x, int y) {

int armor = playerEntity.getArmorValue();
var playerEntity = getCameraPlayer();
var armorslots = playerEntity.getArmorSlots();

Dictionary<ArmorMaterial, Number> defenseDict = new Hashtable<>();

defenseDict = new Hashtable<>();
for (ItemStack slot :
armorslots) {
if (slot.getItem().getClass() != ArmorItem.class && slot.getItem().getClass() != DyeableArmorItem.class)
Expand All @@ -99,45 +111,64 @@ public void renderArmorBar(GuiGraphics graphics, Player playerEntity, int x, int
}
}

var current = getHighestNumericValue(defenseDict);

int xrigid;
for(int w = 0; w < 10; ++w) {

if (current == null || defenseDict.get(current).intValue() <= 0)
current = getHighestNumericValue(defenseDict);
current = getHighestNumericValue(defenseDict);
//instance.push(s);

var Vvalue = switch (current != null? current.getName().toLowerCase() : "null") {
case "diamond" -> 9;
case "leather" -> 0;
case "netherite" -> 18;
case "gold" -> 27;
case "chainmail" -> 36;
default -> 45;
};

}

if (armor > 0) {
xrigid = x + w * 8;
if (w * 2 + 1 < armor) {

graphics.blit(GUI_ICONS_LOCATION, xrigid, y, 238, Vvalue, 9, 9);
if (current != null)
defenseDict.put(current, defenseDict.get(current).intValue() - 2);
}

if (w * 2 + 1 == armor) {
graphics.blit(GUI_ICONS_LOCATION, xrigid, y, 229, Vvalue, 9, 9);
if (current != null)
defenseDict.put(current, defenseDict.get(current).intValue() - 1);
}
public <K> K getHighestNumericValue(Dictionary<K, Number> dict) {
K highVal = null;
Number prevVal = 0;
for (Iterator<K> it = dict.keys().asIterator(); it.hasNext(); ) {
K key = it.next();

if (w * 2 + 1 > armor) {
graphics.blit(GUI_ICONS_LOCATION, xrigid, y, 220, Vvalue, 9, 9);
}
if (dict.get(key).doubleValue() > prevVal.doubleValue()) {
highVal = key;
prevVal = dict.get(key);
}
}

return highVal;
}

// public void renderArmorBar(GuiGraphics graphics, Player playerEntity, int x, int y) {
//
// int xrigid;
// for(int w = 0; w < 10; ++w) {
//
// if (current == null || defenseDict.get(current).intValue() <= 0)
// current = getHighestNumericValue(defenseDict);
//
// var Vvalue = switch (current != null? current.getName().toLowerCase() : "null") {
// case "diamond" -> 9;
// case "leather" -> 0;
// case "netherite" -> 18;
// case "gold" -> 27;
// case "chainmail" -> 36;
// default -> 45;
// };
//
//
// if (armor > 0) {
// xrigid = x + w * 8;
// if (w * 2 + 1 < armor) {
//
// graphics.blit(GUI_ICONS_LOCATION, xrigid, y, 238, Vvalue, 9, 9);
//
// }
//
// if (w * 2 + 1 == armor) {
// graphics.blit(GUI_ICONS_LOCATION, xrigid, y, 229, Vvalue, 9, 9);
//
// }
//
// if (w * 2 + 1 > armor) {
// graphics.blit(GUI_ICONS_LOCATION, xrigid, y, 220, Vvalue, 9, 9);
// }
// }
// }
// }


}

0 comments on commit f26da4b

Please sign in to comment.