27
27
import com .mojang .blaze3d .systems .RenderSystem ;
28
28
import com .mojang .blaze3d .vertex .PoseStack ;
29
29
import dev .galacticraft .machinelib .api .block .entity .MachineBlockEntity ;
30
- import dev .galacticraft .machinelib .api .machine .MachineRenderData ;
31
30
import dev .galacticraft .machinelib .api .machine .configuration .AccessLevel ;
31
+ import dev .galacticraft .machinelib .api .machine .configuration .IOConfig ;
32
32
import dev .galacticraft .machinelib .api .machine .configuration .IOFace ;
33
33
import dev .galacticraft .machinelib .api .machine .configuration .RedstoneMode ;
34
34
import dev .galacticraft .machinelib .api .menu .MachineMenu ;
70
70
import net .minecraft .world .item .ItemStack ;
71
71
import net .minecraft .world .item .Items ;
72
72
import net .minecraft .world .level .block .entity .SkullBlockEntity ;
73
+ import net .minecraft .world .level .block .state .BlockState ;
73
74
import org .jetbrains .annotations .ApiStatus ;
74
75
import org .jetbrains .annotations .NotNull ;
75
76
import org .jetbrains .annotations .Nullable ;
@@ -191,8 +192,8 @@ public class MachineScreen<Machine extends MachineBlockEntity, Menu extends Mach
191
192
* The height of the capacitor.
192
193
*/
193
194
protected int capacitorHeight = 48 ;
194
- protected @ NotNull MachineRenderData renderData ;
195
195
private @ Nullable MachineBakedModel model ;
196
+ private BlockState previousState ;
196
197
197
198
/**
198
199
* Creates a new screen from the given screen handler.
@@ -205,7 +206,6 @@ protected MachineScreen(@NotNull Menu menu, @NotNull Component title, @NotNull R
205
206
super (menu , menu .playerInventory , title );
206
207
207
208
this .texture = texture ;
208
- this .renderData = menu .configuration ;
209
209
210
210
UUID owner = this .menu .security .getOwner () == null ? this .menu .player .getUUID () : this .menu .security .getOwner ();
211
211
this .owner = SkullBlockEntity .fetchGameProfile (owner ).thenApply (o -> o .orElse (new GameProfile (owner , "???" )));
@@ -233,10 +233,22 @@ protected void init() {
233
233
this .titleLabelX = (this .imageWidth - this .font .width (this .title )) / 2 ;
234
234
235
235
if (this .minecraft .getModelManager ().getBlockModelShaper ().getBlockModel (this .menu .be .getBlockState ()) instanceof MachineBakedModel model ) {
236
+ this .previousState = this .menu .be .getBlockState ();
236
237
this .model = model ;
237
238
}
238
239
}
239
240
241
+ @ Override
242
+ protected void containerTick () {
243
+ super .containerTick ();
244
+ if (!this .menu .be .getBlockState ().equals (this .previousState )) {
245
+ this .previousState = this .menu .be .getBlockState ();
246
+ if (this .minecraft .getModelManager ().getBlockModelShaper ().getBlockModel (this .menu .be .getBlockState ()) instanceof MachineBakedModel model ) {
247
+ this .model = model ;
248
+ }
249
+ }
250
+ }
251
+
240
252
/**
241
253
* Appends additional information to the capacitor's tooltip.
242
254
*
@@ -303,12 +315,12 @@ protected void drawConfigurationPanels(@NotNull GuiGraphics graphics, int mouseX
303
315
.setStyle (Constant .Text .GRAY_STYLE ), PANEL_TITLE_X , PANEL_TITLE_Y , 0xFFFFFFFF );
304
316
305
317
RenderSystem .setShaderTexture (0 , InventoryMenu .BLOCK_ATLAS );
306
- this .drawMachineFace (graphics , TOP_FACE_X , TOP_FACE_Y , this .renderData , BlockFace .TOP );
307
- this .drawMachineFace (graphics , LEFT_FACE_X , LEFT_FACE_Y , this .renderData , BlockFace .LEFT );
308
- this .drawMachineFace (graphics , FRONT_FACE_X , FRONT_FACE_Y , this .renderData , BlockFace .FRONT );
309
- this .drawMachineFace (graphics , RIGHT_FACE_X , RIGHT_FACE_Y , this .renderData , BlockFace .RIGHT );
310
- this .drawMachineFace (graphics , BACK_FACE_X , BACK_FACE_Y , this .renderData , BlockFace .BACK );
311
- this .drawMachineFace (graphics , BOTTOM_FACE_X , BOTTOM_FACE_Y , this .renderData , BlockFace .BOTTOM );
318
+ this .drawMachineFace (graphics , TOP_FACE_X , TOP_FACE_Y , this .menu . configuration , BlockFace .TOP );
319
+ this .drawMachineFace (graphics , LEFT_FACE_X , LEFT_FACE_Y , this .menu . configuration , BlockFace .LEFT );
320
+ this .drawMachineFace (graphics , FRONT_FACE_X , FRONT_FACE_Y , this .menu . configuration , BlockFace .FRONT );
321
+ this .drawMachineFace (graphics , RIGHT_FACE_X , RIGHT_FACE_Y , this .menu . configuration , BlockFace .RIGHT );
322
+ this .drawMachineFace (graphics , BACK_FACE_X , BACK_FACE_Y , this .menu . configuration , BlockFace .BACK );
323
+ this .drawMachineFace (graphics , BOTTOM_FACE_X , BOTTOM_FACE_Y , this .menu . configuration , BlockFace .BOTTOM );
312
324
poseStack .popPose ();
313
325
}
314
326
if (Tab .STATS .isOpen ()) {
@@ -366,13 +378,12 @@ protected void drawTitle(@NotNull GuiGraphics graphics) {
366
378
* @param graphics the gui graphics
367
379
* @param x the x position to draw at
368
380
* @param y the y position to draw at
369
- * @param data the machine's extra render data
381
+ * @param ioConfig the machine's extra render data
370
382
* @param face the face to draw
371
383
*/
372
- private void drawMachineFace (@ NotNull GuiGraphics graphics , int x , int y , @ NotNull MachineRenderData data , @ NotNull BlockFace face ) {
373
- IOFace machineFace = menu .configuration .get (face );
384
+ private void drawMachineFace (@ NotNull GuiGraphics graphics , int x , int y , @ NotNull IOConfig ioConfig , @ NotNull BlockFace face ) {
374
385
if (this .model != null ) {
375
- graphics .blit (x , y , 0 , MACHINE_FACE_SIZE , MACHINE_FACE_SIZE , model .getSprite (face , data , machineFace . getType (), machineFace . getFlow () ));
386
+ graphics .blit (x , y , 0 , MACHINE_FACE_SIZE , MACHINE_FACE_SIZE , this . model .getSprite (this . menu . be . getBlockState (), face , ioConfig ));
376
387
}
377
388
}
378
389
0 commit comments