Skip to content

Commit

Permalink
Adjust the scale of armor stands rendered in the nearby glowing list
Browse files Browse the repository at this point in the history
Display the configured size when hovering, display an underline on the coordinate if it has a base-plate enabled
  • Loading branch information
Mrbysco committed Nov 26, 2024
1 parent 73b5a81 commit 190326b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.mrbysco.armorposer.client.gui.widgets;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mrbysco.armorposer.client.gui.ArmorGlowScreen;
import com.mrbysco.armorposer.mixin.ArmorStandAccessor;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ObjectSelectionList;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.decoration.ArmorStand;
import org.joml.Quaternionf;
import org.joml.Vector3f;
Expand Down Expand Up @@ -59,26 +64,37 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
public class ListEntry extends Entry<ListEntry> {
private final ArmorGlowScreen parent;
private final ArmorStand armorStand;
private final float scale;
private final boolean showPlate;
private final boolean locked;

ListEntry(ArmorStand armorStand, ArmorGlowScreen parent) {
this.armorStand = armorStand;
this.parent = parent;
this.scale = armorStand.getScale();
this.showPlate = armorStand.showBasePlate();
this.locked = ((ArmorStandAccessor)armorStand).armorposer$getDisabledSlots() != 0;
}

@Override
public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, int entryWidth, int entryHeight,
int mouseX, int mouseY, boolean hovered, float partialTicks) {
Font font = this.parent.getScreenFont();
renderScrollingString(guiGraphics, font, getPositionComponent(), left + 36, top + 10, left + width - 18, top + 20, 0xFFFFFF);
if (isMouseOver(mouseX, mouseY)) {
Component component = Component.translatable("armorposer.gui.armor_list.stats", scale);

renderPose(guiGraphics, left + 16, top + 28, 15);
guiGraphics.renderTooltip(font, component, mouseX, mouseY);
}

renderPose(guiGraphics, left + 16, top + 28, (1.0f / scale) * 15);
}

public ArmorStand getArmorStand() {
return armorStand;
}

public void renderPose(GuiGraphics guiGraphics, int xPos, int yPos, int size) {
public void renderPose(GuiGraphics guiGraphics, int xPos, int yPos, float size) {
if (armorStand != null) {
InventoryScreen.renderEntityInInventory(guiGraphics, xPos, yPos, size,
ARMOR_STAND_TRANSLATION, ARMOR_STAND_ANGLE, (Quaternionf) null, this.armorStand);
Expand All @@ -98,7 +114,10 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}

public Component getPositionComponent() {
return Component.literal(getArmorStand().blockPosition().toShortString());
MutableComponent component = Component.literal(getArmorStand().blockPosition().toShortString());
if (this.showPlate)
component = component.withStyle(ChatFormatting.UNDERLINE);
return component;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mrbysco.armorposer.mixin;

import net.minecraft.world.entity.decoration.ArmorStand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(ArmorStand.class)
public interface ArmorStandAccessor {
@Accessor("disabledSlots")
int armorposer$getDisabledSlots();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"armorposer.gui.armor_list.list": "Armor Stands",
"armorposer.gui.armor_list.locate": "Locate",
"armorposer.gui.armor_list.modify": "Modify",
"armorposer.gui.armor_list.stats": "Scale %s",
"armorposer.gui.delete_poose.message": "Are you sure you want to remove this pose?",
"armorposer.gui.delete_poose.title": "Delete pose",
"armorposer.gui.label.body": "Body",
Expand Down
3 changes: 2 additions & 1 deletion fabric/src/main/resources/armorposer.fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"refmap": "armorposer.refmap.json",
"compatibilityLevel": "JAVA_21",
"mixins": [
"ArmorStandMixin"
"ArmorStandMixin",
"ArmorStandAccessor"
],
"client": [
"MinecraftMixin"
Expand Down
1 change: 1 addition & 0 deletions forge/src/main/resources/armorposer.neoforge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "com.mrbysco.armorposer.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"ArmorStandAccessor"
],
"client": [
"MinecraftMixin"
Expand Down

0 comments on commit 190326b

Please sign in to comment.