22
33import com .mojang .blaze3d .platform .InputConstants ;
44import de .ellpeck .prettypipes .PrettyPipes ;
5- import de .ellpeck .prettypipes .misc .ItemTerminalWidget ;
65import de .ellpeck .prettypipes .packets .PacketButton ;
7- import de .ellpeck .prettypipes .packets .PacketGhostSlot ;
8- import de .ellpeck .prettypipes .terminal .CraftingTerminalBlockEntity ;
96import net .minecraft .client .gui .GuiGraphics ;
107import net .minecraft .client .gui .components .Button ;
118import net .minecraft .client .gui .components .Tooltip ;
129import net .minecraft .client .gui .screens .Screen ;
1310import net .minecraft .network .chat .Component ;
1411import net .minecraft .resources .ResourceLocation ;
1512import net .minecraft .world .entity .player .Inventory ;
16- import net .minecraft .world .inventory .Slot ;
1713import net .neoforged .neoforge .network .PacketDistributor ;
1814
19- import java .util .ArrayList ;
2015import java .util .Arrays ;
2116import java .util .List ;
22- import java .util .Optional ;
2317
2418public class CraftingTerminalGui extends ItemTerminalGui {
2519
2620 private static final ResourceLocation TEXTURE = ResourceLocation .fromNamespaceAndPath (PrettyPipes .ID , "textures/gui/crafting_terminal.png" );
2721 private Button requestButton ;
2822 private Button sendBackButton ;
2923
30- private ItemTerminalWidget draggedItem ;
31- private boolean dragging ;
32-
3324 public CraftingTerminalGui (ItemTerminalContainer screenContainer , Inventory inv , Component titleIn ) {
3425 super (screenContainer , inv , titleIn );
3526 this .imageWidth = 256 ;
@@ -68,23 +59,24 @@ public void containerTick() {
6859
6960 @ Override
7061 protected void renderLabels (GuiGraphics graphics , int mouseX , int mouseY ) {
71- super .renderLabels (graphics , mouseX , mouseY );
72- var container = this . getCraftingContainer ();
73- var tile = container . getTile ();
74- for ( var i = 0 ; i < tile . ghostItems . getSlots (); i ++) {
75- if (! tile .craftItems . getStackInSlot ( i ). isEmpty ())
76- continue ;
77- var ghost = tile . ghostItems . getStackInSlot ( i ) ;
78- if ( ghost . isEmpty ())
79- continue ;
80- var finalI = i ;
81- var slot = container . slots . stream (). filter ( s -> s . container == container . craftInventory && s . getSlotIndex () == finalI ). findFirst (). orElse ( null ) ;
82- if ( slot == null )
83- continue ;
84- graphics . renderItem ( ghost , slot . x , slot . y ) ;
85- graphics .renderItemDecorations ( this . font , ghost , slot .x , slot .y , "0" );
86- }
62+ super .renderLabels (graphics , mouseX , mouseY );
63+
64+ var container = this . getCraftingContainer ();
65+ var tile = container . getTile ();
66+ for ( var i = 0 ; i < tile .ghostItems . getSlots (); i ++) {
67+ if (! tile . craftItems . getStackInSlot ( i ). isEmpty ())
68+ continue ;
69+ var ghost = tile . ghostItems . getStackInSlot ( i );
70+ if ( ghost . isEmpty ())
71+ continue ;
72+ var finalI = i ;
73+ var slot = container . slots . stream (). filter ( s -> s . container == container . craftInventory && s . getSlotIndex () == finalI ). findFirst (). orElse ( null );
74+ if ( slot == null )
75+ continue ;
76+ graphics .renderItem ( ghost , slot .x , slot .y );
77+ graphics . renderItemDecorations ( this . font , ghost , slot . x , slot . y , "0" );
8778 }
79+ }
8880
8981 @ Override
9082 protected ResourceLocation getTexture () {
@@ -100,57 +92,4 @@ protected CraftingTerminalContainer getCraftingContainer() {
10092 return (CraftingTerminalContainer ) this .menu ;
10193 }
10294
103- @ Override
104- public boolean mouseClicked (double mouseX , double mouseY , int button ) {
105- if (button == 0 && this .draggedItem == null ) {
106- this .getChildAt (mouseX ,mouseY ).ifPresent (widget -> this .draggedItem = widget instanceof ItemTerminalWidget terminalWidget && !terminalWidget .stack .isEmpty ()? terminalWidget : null );
107- }
108- return super .mouseClicked (mouseX , mouseY , button );
109- }
110-
111- @ Override
112- public boolean mouseReleased (double mouseX , double mouseY , int button ) {
113-
114- Slot curSlot = getSlotUnderMouse ();
115- if (draggedItem !=null && !draggedItem .stack .isEmpty () && curSlot !=null && curSlot .index >=0 && curSlot .index <9 ) {
116- List <PacketGhostSlot .Entry > stacks = new ArrayList <>();
117- if ( menu .tile instanceof CraftingTerminalBlockEntity craftingTerminalBlockEntity ) {
118- for (int i = 0 ; i < craftingTerminalBlockEntity .ghostItems .getSlots (); i ++) {
119- if (i != curSlot .index -1 )
120- stacks .add (i , new PacketGhostSlot .Entry (Optional .of (List .of (craftingTerminalBlockEntity .ghostItems .getStackInSlot (i ))), Optional .empty ()));
121- else {
122- stacks .add (i , new PacketGhostSlot .Entry (Optional .of (List .of (draggedItem .stack )), Optional .empty ()));
123- }
124-
125- }
126- PacketDistributor .sendToServer (new PacketGhostSlot (craftingTerminalBlockEntity .getBlockPos (), stacks ));
127- }
128- }
129- dragging =false ;
130- draggedItem =null ;
131- return super .mouseReleased (mouseX , mouseY , button );
132-
133- }
134-
135- @ Override
136- public boolean mouseDragged (double mouseX , double mouseY , int i , double j , double k ) {
137- if (this .draggedItem != null ) {
138- double distance = j *j +k *k ;
139- if (distance >2 )
140- dragging =true ;
141- }
142- return super .mouseDragged (mouseX , mouseY , i , j , k );
143- }
144-
145- @ Override
146- public void render (GuiGraphics graphics , int mouseX , int mouseY , float partialTicks ) {
147- super .render (graphics , mouseX , mouseY , partialTicks );
148- if (draggedItem !=null && dragging ) {
149- graphics .pose ().pushPose ();
150- graphics .pose ().translate (0 , 0 , 200 );
151- graphics .renderItem (draggedItem .stack , mouseX -9 , mouseY - 9 );
152- graphics .pose ().popPose ();
153- }
154- }
155-
15695}
0 commit comments