17
17
import java .util .ArrayList ;
18
18
import java .util .List ;
19
19
20
+ import org .lwjgl .opengl .GL11 ;
21
+
20
22
import net .minecraft .client .gui .FontRenderer ;
21
23
import net .minecraft .client .gui .GuiEnchantment ;
22
24
import net .minecraft .client .resources .I18n ;
@@ -36,7 +38,6 @@ public class GuiEnchantmentWrapper extends GuiEnchantment {
36
38
private static final FontRenderer dummyFontRenderer = new DummyFontRenderer ();
37
39
private static final long SCROLL_PERIOD_MS = 5000 ;
38
40
private static final long SCROLL_PAUSE_MS = 1000 ;
39
- private static ClippedFontRenderer clippedRenderer = null ;
40
41
41
42
private final EnchantmentWorker worker ;
42
43
private final InventoryPlayer inventory ;
@@ -83,17 +84,19 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
83
84
if (lastState .observation != ((ContainerEnchantmentWrapper ) inventorySlots ).lastObservation ) {
84
85
return ; // Out-of-sync, happens when the GUI is closed with an item still present
85
86
}
87
+ FontRenderer renderer = mc .fontRenderer ;
86
88
87
- if (clippedRenderer == null ) {
88
- clippedRenderer = new ClippedFontRenderer (mc .fontRenderer );
89
- }
90
-
89
+ // Use the scissor test to clip scrolling/oversize text to within the GUI. We have to
90
+ // rescale to get screen coordinates from GUI (scaled) coordinates.
91
91
int midX = (width - xSize ) / 2 ;
92
92
int midY = (height - ySize ) / 2 ;
93
93
final int leftBound = 78 ;
94
94
final int rightBound = 166 ;
95
- clippedRenderer .clipMinX = midX + leftBound ;
96
- clippedRenderer .clipMaxX = midX + rightBound ;
95
+ int clipMinX = (midX + leftBound ) * mc .displayWidth / width ;
96
+ int scissorWidth = (rightBound - leftBound ) * mc .displayWidth / width ;
97
+ GL11 .glEnable (GL11 .GL_SCISSOR_TEST );
98
+ GL11 .glScissor (clipMinX , 0 , scissorWidth , mc .displayHeight );
99
+
97
100
float scrollFraction = getScrollFraction ();
98
101
for (int i = 0 ; i < 3 ; ++i ) {
99
102
String [] enchants = lastState .enchants [i ];
@@ -102,10 +105,10 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
102
105
}
103
106
104
107
String ench = enchants [0 ];
105
- int stringWidth = clippedRenderer .getStringWidth (ench );
108
+ int stringWidth = renderer .getStringWidth (ench );
106
109
float adjust = (stringWidth <= rightBound - leftBound ? 0.5F : scrollFraction )
107
110
* (rightBound - leftBound - stringWidth );
108
- clippedRenderer .drawString (ench , midX + leftBound + adjust ,
111
+ renderer .drawString (ench , midX + leftBound + adjust ,
109
112
midY + 15 + 19 * i , 0x222222 , false );
110
113
111
114
int [] enchantCounts = lastState .counts [i ];
@@ -125,9 +128,10 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
125
128
int total = (int ) (((acc * 200L + 1 ) / enchantCounts [0 ]) >>> 1 );
126
129
plusX = String .format ("%d.%02d" , total / 100 , total % 100 );
127
130
}
128
- clippedRenderer .drawString (I18n .format ("enchantmentrevealer.text.plusx" , plusX ),
131
+ renderer .drawString (I18n .format ("enchantmentrevealer.text.plusx" , plusX ),
129
132
midX + leftBound + 2 , midY + 24 + 19 * i , 0x222222 );
130
133
}
134
+ GL11 .glDisable (GL11 .GL_SCISSOR_TEST );
131
135
}
132
136
133
137
private float getScrollFraction () {
0 commit comments