Skip to content

Commit cb181ce

Browse files
committed
Slot decorations
1 parent a672182 commit cb181ce

File tree

4 files changed

+128
-3
lines changed

4 files changed

+128
-3
lines changed

src/main/java/llc/redstone/hysentials/config/hysentialMods/FormattingConfig.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package llc.redstone.hysentials.config.hysentialMods;
22

33
import cc.polyfrost.oneconfig.config.Config;
4+
import cc.polyfrost.oneconfig.config.annotations.*;
45
import cc.polyfrost.oneconfig.config.annotations.Button;
5-
import cc.polyfrost.oneconfig.config.annotations.CustomOption;
6-
import cc.polyfrost.oneconfig.config.annotations.Switch;
6+
import cc.polyfrost.oneconfig.config.annotations.Color;
77
import cc.polyfrost.oneconfig.config.core.ConfigUtils;
88
import cc.polyfrost.oneconfig.config.core.OneColor;
99
import cc.polyfrost.oneconfig.config.data.Mod;
@@ -117,6 +117,40 @@ public void openRankHexConfig() {
117117
)
118118
public static boolean hoverOutlineColor = true;
119119

120+
@Switch(
121+
name = "Slot Decoration",
122+
category = "General",
123+
subcategory = "Slot Decoration",
124+
description = "Enable slot decorations."
125+
)
126+
public static boolean slotDecoration = true;
127+
128+
@Dropdown(
129+
name = "Slot Decoration Style",
130+
category = "General",
131+
subcategory = "Slot Decoration",
132+
description = "Change the style of the slot decoration.",
133+
options = {"Circle", "Rectangle"}
134+
)
135+
public static int slotDecorationStyle = 0;
136+
137+
@Color(
138+
name = "Slot Decoration Alpha",
139+
category = "General",
140+
subcategory = "Slot Decoration",
141+
description = "Change the alpha of the slot decoration color."
142+
)
143+
public static OneColor slotDecorationColor = new OneColor(0, 0, 0, 200);
144+
145+
@Slider(
146+
name = "Slot Decoration Color Offset",
147+
category = "General",
148+
subcategory = "Slot Decoration",
149+
description = "Change the color offset of the slot decoration color.",
150+
min = -255,
151+
max = 255
152+
)
153+
public static int slotDecorationColorOffset = -20;
120154

121155
@RankAnnotation(
122156
name = "Default Rank",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package llc.redstone.hysentials.mixin;
2+
3+
import llc.redstone.hysentials.config.hysentialMods.FormattingConfig;
4+
import llc.redstone.hysentials.util.ImageIconRenderer;
5+
import llc.redstone.hysentials.util.Renderer;
6+
import net.minecraft.client.gui.inventory.GuiContainer;
7+
import net.minecraft.client.renderer.GlStateManager;
8+
import net.minecraft.client.renderer.Tessellator;
9+
import net.minecraft.client.renderer.WorldRenderer;
10+
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
11+
import net.minecraft.inventory.Slot;
12+
import net.minecraft.util.MathHelper;
13+
import org.spongepowered.asm.mixin.Mixin;
14+
import org.spongepowered.asm.mixin.Unique;
15+
import org.spongepowered.asm.mixin.injection.At;
16+
import org.spongepowered.asm.mixin.injection.Inject;
17+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
18+
19+
import java.awt.*;
20+
21+
import static net.minecraftforge.fml.client.config.GuiUtils.drawGradientRect;
22+
23+
@Mixin(value = GuiContainer.class, priority = Integer.MAX_VALUE)
24+
public abstract class SlotDecorationMixin {
25+
@Inject(method = "drawSlot", at = @At(value = "HEAD"))
26+
public void drawSlot(Slot slotIn, CallbackInfo ci) {
27+
if (FormattingConfig.slotDecoration) {
28+
int style = FormattingConfig.slotDecorationStyle;
29+
int i = slotIn.xDisplayPosition;
30+
int j = slotIn.yDisplayPosition;
31+
if (slotIn.getHasStack()) {
32+
String s = slotIn.getStack().getDisplayName();
33+
String hex = ImageIconRenderer.getHexFromString(s, true);
34+
if (hex == null || hex.isEmpty()) {
35+
return;
36+
}
37+
Color c = Color.decode(hex);
38+
int offset = FormattingConfig.slotDecorationColorOffset;
39+
c = new Color(c.getRed() + offset, c.getGreen() + offset, c.getBlue() + offset, FormattingConfig.slotDecorationColor.getAlpha());
40+
int c2 = c.getRGB();
41+
if (style == 0) {
42+
GlStateManager.pushMatrix();
43+
GlStateManager.disableLighting();
44+
GlStateManager.disableDepth();
45+
Renderer.drawCircle(c2, i + 8, j + 8, 8, 100, 5);
46+
GlStateManager.enableLighting();
47+
GlStateManager.enableDepth();
48+
GlStateManager.popMatrix();
49+
} else {
50+
drawGradientRect(0, i, j, i + 16, j + 16, c2, c2);
51+
}
52+
}
53+
}
54+
}
55+
}

src/main/java/llc/redstone/hysentials/util/Renderer.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.function.Consumer;
3030

3131
import static cc.polyfrost.oneconfig.renderer.TextRenderer.drawBorderedText;
32+
import static java.lang.Math.*;
3233

3334
public class Renderer {
3435
public Renderer() {
@@ -92,8 +93,42 @@ public static void drawString(String text, int x, int y, float size, boolean sha
9293
GlStateManager.popMatrix();
9394
}
9495

96+
private static final float TWO_PI = 2.0f * (float) PI;
9597

98+
public static void drawCircle(long color, float x, float y, float radius, int steps, int drawMode) {
99+
float theta = TWO_PI / steps;
100+
float cos = (float) cos(theta);
101+
float sin = (float) sin(theta);
96102

103+
float xHolder;
104+
float circleX = 1f;
105+
float circleY = 0f;
106+
107+
GlStateManager.enableBlend();
108+
GlStateManager.disableTexture2D();
109+
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
110+
111+
doColor(color);
112+
113+
worldRenderer.begin(drawMode, DefaultVertexFormats.POSITION);
114+
115+
for (int i = 0; i <= steps; i++) {
116+
worldRenderer.pos(x, y, 0.0).endVertex();
117+
worldRenderer.pos((circleX * radius + x), (circleY * radius + y), 0.0).endVertex();
118+
xHolder = circleX;
119+
circleX = cos * circleX - sin * circleY;
120+
circleY = sin * xHolder + cos * circleY;
121+
worldRenderer.pos((circleX * radius + x), (circleY * radius + y), 0.0).endVertex();
122+
}
123+
124+
tessellator.draw();
125+
126+
GlStateManager.color(1f, 1f, 1f, 1f);
127+
GlStateManager.enableTexture2D();
128+
GlStateManager.disableBlend();
129+
130+
finishDraw();
131+
}
97132

98133
public static void drawRect(long color, float x, float y, float width, float height) {
99134
float[] pos = {x, y, x + width, y + height};

src/main/resources/mixins.hysentials.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"PlayerRendererMixin",
2424
"RenderItemMixin",
2525
"RenderLivingMixin",
26-
"RenderMixin"
26+
"RenderMixin",
27+
"SlotDecorationMixin"
2728
]
2829
}

0 commit comments

Comments
 (0)