11package pro .mikey .xray .gui ;
22
33import com .mojang .blaze3d .platform .GlStateManager ;
4- import com .mojang .blaze3d .platform .Lighting ;
54import com .mojang .blaze3d .systems .RenderSystem ;
6- import com .mojang .blaze3d .vertex .PoseStack ;
75import net .minecraft .client .Minecraft ;
86import net .minecraft .client .gui .Font ;
97import net .minecraft .client .gui .GuiGraphics ;
10- import net .minecraft .client .gui .components .AbstractSelectionList ;
118import net .minecraft .client .gui .components .Button ;
129import net .minecraft .client .gui .components .EditBox ;
1310import net .minecraft .client .gui .components .ObjectSelectionList ;
2724import net .minecraft .world .phys .Vec3 ;
2825import pro .mikey .xray .ClientController ;
2926import pro .mikey .xray .Configuration ;
27+ import pro .mikey .xray .Utils ;
3028import pro .mikey .xray .XRay ;
29+ import pro .mikey .xray .gui .manage .BlockListScreen ;
3130import pro .mikey .xray .gui .manage .GuiAddBlock ;
32- import pro .mikey .xray .gui .manage .GuiBlockList ;
3331import pro .mikey .xray .gui .manage .GuiEdit ;
3432import pro .mikey .xray .gui .utils .GuiBase ;
35- import pro .mikey .xray .gui .utils .ScrollingList ;
3633import pro .mikey .xray .gui .utils .SupportButton ;
3734import pro .mikey .xray .keybinding .KeyBindings ;
3835import pro .mikey .xray .store .BlockStore ;
4845import java .util .stream .Collectors ;
4946
5047public class GuiSelectionScreen extends GuiBase {
51- private static final ResourceLocation CIRCLE = new ResourceLocation (XRay .PREFIX_GUI + "circle.png" );
48+ private static final ResourceLocation CIRCLE = Utils . rlFull (XRay .PREFIX_GUI + "circle.png" );
5249
5350 private Button distButtons ;
5451 private EditBox search ;
@@ -85,15 +82,15 @@ public void init() {
8582 this .render = Minecraft .getInstance ().getItemRenderer ();
8683 this .children ().clear ();
8784
88- this .scrollList = new ScrollingBlockList ((getWidth () / 2 ) - 37 , getHeight () / 2 + 10 , 203 , 185 , this .itemList , this );
85+ this .scrollList = new ScrollingBlockList ((( getWidth () / 2 ) - ( 203 / 2 ) ) - 37 , getHeight () / 2 + 10 , 203 , 185 , this .itemList , this );
8986 addRenderableWidget (this .scrollList );
9087
9188 this .search = new EditBox (getFontRender (), getWidth () / 2 - 137 , getHeight () / 2 - 105 , 202 , 18 , Component .empty ());
9289 this .search .setCanLoseFocus (true );
9390
9491 // side bar buttons
9592 addRenderableWidget (new SupportButtonInner ((getWidth () / 2 ) + 79 , getHeight () / 2 - 60 , 120 , 20 , I18n .get ("xray.input.add" ), "xray.tooltips.add_block" , button -> {
96- getMinecraft ().setScreen (new GuiBlockList ());
93+ getMinecraft ().setScreen (new BlockListScreen ());
9794 }));
9895 addRenderableWidget (new SupportButtonInner (getWidth () / 2 + 79 , getHeight () / 2 - 38 , 120 , 20 , I18n .get ("xray.input.add_hand" ), "xray.tooltips.add_block_in_hand" , button -> {
9996 ItemStack handItem = getMinecraft ().player .getItemInHand (InteractionHand .MAIN_HAND );
@@ -247,14 +244,26 @@ public SupportButtonInner(int widthIn, int heightIn, int width, int height, Stri
247244 }
248245 }
249246
250- static class ScrollingBlockList extends ScrollingList <ScrollingBlockList .BlockSlot > {
247+ class ScrollingBlockList extends ObjectSelectionList <ScrollingBlockList .BlockSlot > {
251248 static final int SLOT_HEIGHT = 35 ;
252249 public GuiSelectionScreen parent ;
253250
254251 ScrollingBlockList (int x , int y , int width , int height , List <BlockData > blocks , GuiSelectionScreen parent ) {
255- super (x , y , width , height , SLOT_HEIGHT );
252+ super (GuiSelectionScreen . this . minecraft , width - 2 , height , ( GuiSelectionScreen . this . height / 2 ) - ( height / 2 ) + 10 , SLOT_HEIGHT );
256253 this .updateEntries (blocks );
257254 this .parent = parent ;
255+
256+ this .setX (x + 2 );
257+ }
258+
259+ @ Override
260+ public int getRowWidth () {
261+ return 188 ;
262+ }
263+
264+ @ Override
265+ protected int getScrollbarPosition () {
266+ return this .getX () + this .getRowWidth () + 6 ;
258267 }
259268
260269 public void setSelected (@ Nullable BlockSlot entry , int mouse ) {
@@ -295,16 +304,11 @@ public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, int
295304
296305 Font font = Minecraft .getInstance ().font ;
297306
298- guiGraphics .drawString (font , blockData .getEntryName (), left + 35 , top + 7 , 0xFFFFFF );
299- guiGraphics .drawString (font , blockData .isDrawing () ? "Enabled" : "Disabled" , left + 35 , top + 17 , blockData .isDrawing () ? Color .GREEN .getRGB () : Color .RED .getRGB ());
300-
301- guiGraphics .renderItem (blockData .getItemStack (), left + 8 , top + 7 );
302- guiGraphics .renderItemDecorations (font , blockData .getItemStack (), left + 8 , top + 7 ); // TODO: verify
307+ guiGraphics .drawString (font , blockData .getEntryName (), left + 25 , top + 7 , 0xFFFFFF );
308+ guiGraphics .drawString (font , blockData .isDrawing () ? "Enabled" : "Disabled" , left + 25 , top + 17 , blockData .isDrawing () ? Color .GREEN .getRGB () : Color .RED .getRGB ());
303309
304- // old from < 1.20
305- // Lighting.setupFor3DItems();
306- // Minecraft.getInstance().getItemRenderer().renderAndDecorateItem(stack, blockData.getItemStack(), left + 8, top + 7);
307- // Lighting.setupForFlatItems();
310+ guiGraphics .renderItem (blockData .getItemStack (), left , top + 7 );
311+ guiGraphics .renderItemDecorations (font , blockData .getItemStack (), left , top + 7 ); // TODO: verify
308312
309313 if (mouseX > left && mouseX < (left + entryWidth ) && mouseY > top && mouseY < (top + entryHeight ) && mouseY < (this .parent .getY () + this .parent .getHeight ()) && mouseY > this .parent .getY ()) {
310314 guiGraphics .renderTooltip (
@@ -323,9 +327,9 @@ public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, int
323327 RenderSystem .blendFunc (
324328 GlStateManager .SourceFactor .SRC_ALPHA , GlStateManager .DestFactor .ONE_MINUS_SRC_ALPHA );
325329 RenderSystem .setShaderColor (0 , 0 , 0 , .5f );
326- guiGraphics .blit (GuiSelectionScreen .CIRCLE , (left + entryWidth ) - 35 , (int ) (top + (entryHeight / 2f ) - 9 ), 0 , 0 , 14 , 14 , 14 , 14 );
330+ guiGraphics .blit (GuiSelectionScreen .CIRCLE , (left + entryWidth ) - 23 , (int ) (top + (entryHeight / 2f ) - 9 ), 0 , 0 , 14 , 14 , 14 , 14 );
327331 RenderSystem .setShaderColor (color .getRed () / 255f , color .getGreen () / 255f , color .getBlue () / 255f , 1 );
328- guiGraphics .blit (GuiSelectionScreen .CIRCLE , (left + entryWidth ) - 33 , (int ) (top + (entryHeight / 2f ) - 7 ), 0 , 0 , 10 , 10 , 10 , 10 );
332+ guiGraphics .blit (GuiSelectionScreen .CIRCLE , (left + entryWidth ) - 21 , (int ) (top + (entryHeight / 2f ) - 7 ), 0 , 0 , 10 , 10 , 10 , 10 );
329333 RenderSystem .setShaderColor (1F , 1F , 1F , 1F );
330334 RenderSystem .disableBlend ();
331335 stack .popPose ();
0 commit comments