@@ -1253,15 +1253,17 @@ public enum ScriptActionType {
12531253 String text = ctx .value ("Text" ).asText ();
12541254 String identifier = ctx .value ("Identifier" ).asText ();
12551255
1256- if (DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1257- if (menu .ownedBy (ctx .task ().context ().script ())) {
1258- menu .widgets .add (new ScriptMenuButton (x ,y ,width ,height ,text ,identifier ,ctx .task ().context ().script ()));
1256+ DFScript .MC .send (() -> {
1257+ if (DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1258+ if (menu .ownedBy (ctx .task ().context ().script ())) {
1259+ menu .widgets .add (new ScriptMenuButton (x ,y ,width ,height ,text ,identifier ,ctx .task ().context ().script ()));
1260+ } else {
1261+ OverlayManager .getInstance ().add ("Unable to add button to menu! (Not owned by script)" );
1262+ }
12591263 } else {
1260- OverlayManager .getInstance ().add ("Unable to add button to menu! (Not owned by script )" );
1264+ OverlayManager .getInstance ().add ("Unable to add button to menu! (Unknown menu type )" );
12611265 }
1262- } else {
1263- OverlayManager .getInstance ().add ("Unable to add button to menu! (Unknown menu type)" );
1264- }
1266+ });
12651267 })),
12661268
12671269 ADD_MENU_ITEM (builder -> builder .name ("Add Menu Item" )
@@ -1278,15 +1280,17 @@ public enum ScriptActionType {
12781280 ItemStack item = ScriptValueItem .itemFromValue (ctx .value ("Item" ));
12791281 String identifier = ctx .value ("Identifier" ).asText ();
12801282
1281- if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1282- if (menu .ownedBy (ctx .task ().context ().script ())) {
1283- menu .widgets .add (new ScriptMenuItem (x ,y ,item ,identifier ));
1283+ DFScript .MC .send (() -> {
1284+ if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1285+ if (menu .ownedBy (ctx .task ().context ().script ())) {
1286+ menu .widgets .add (new ScriptMenuItem (x ,y ,item ,identifier ));
1287+ } else {
1288+ OverlayManager .getInstance ().add ("Unable to add item to menu! (Not owned by script)" );
1289+ }
12841290 } else {
1285- OverlayManager .getInstance ().add ("Unable to add item to menu! (Not owned by script )" );
1291+ OverlayManager .getInstance ().add ("Unable to add item to menu! (Unknown menu type )" );
12861292 }
1287- } else {
1288- OverlayManager .getInstance ().add ("Unable to add item to menu! (Unknown menu type)" );
1289- }
1293+ });
12901294 })),
12911295
12921296 ADD_MENU_TEXT (builder -> builder .name ("Add Menu Text" )
@@ -1304,15 +1308,17 @@ public enum ScriptActionType {
13041308 String identifier = ctx .value ("Identifier" ).asText ();
13051309 Text text = ComponentUtil .fromString (ComponentUtil .andsToSectionSigns (rawText ));
13061310
1307- if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1308- if (menu .ownedBy (ctx .task ().context ().script ())) {
1309- menu .widgets .add (new ScriptMenuText (x ,y ,text ,0x333333 , 1 , false , false ,identifier ));
1311+ DFScript .MC .send (() -> {
1312+ if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1313+ if (menu .ownedBy (ctx .task ().context ().script ())) {
1314+ menu .widgets .add (new ScriptMenuText (x ,y ,text ,0x333333 , 1 , false , false ,identifier ));
1315+ } else {
1316+ OverlayManager .getInstance ().add ("Unable to add text to menu! (Not owned by script)" );
1317+ }
13101318 } else {
1311- OverlayManager .getInstance ().add ("Unable to add text to menu! (Not owned by script )" );
1319+ OverlayManager .getInstance ().add ("Unable to add text to menu! (Unknown menu type )" );
13121320 }
1313- } else {
1314- OverlayManager .getInstance ().add ("Unable to add text to menu! (Unknown menu type)" );
1315- }
1321+ });
13161322 })),
13171323
13181324 ADD_MENU_TEXT_FIELD (builder -> builder .name ("Add Menu Text Field" )
@@ -1331,15 +1337,17 @@ public enum ScriptActionType {
13311337 int height = (int ) ctx .value ("Height" ).asNumber ();
13321338 String identifier = ctx .value ("Identifier" ).asText ();
13331339
1334- if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1335- if (menu .ownedBy (ctx .task ().context ().script ())) {
1336- menu .widgets .add (new ScriptMenuTextField ("" ,x ,y ,width ,height ,true ,identifier ));
1340+ DFScript .MC .send (() -> {
1341+ if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1342+ if (menu .ownedBy (ctx .task ().context ().script ())) {
1343+ menu .widgets .add (new ScriptMenuTextField ("" , x , y , width , height , true , identifier ));
1344+ } else {
1345+ OverlayManager .getInstance ().add ("Unable to add text field to menu! (Not owned by script)" );
1346+ }
13371347 } else {
1338- OverlayManager .getInstance ().add ("Unable to add text field to menu! (Not owned by script )" );
1348+ OverlayManager .getInstance ().add ("Unable to add text field to menu! (Unknown menu type )" );
13391349 }
1340- } else {
1341- OverlayManager .getInstance ().add ("Unable to add text field to menu! (Unknown menu type)" );
1342- }
1350+ });
13431351 })),
13441352
13451353 REMOVE_MENU_ELEMENT (builder -> builder .name ("Remove Menu Element" )
@@ -1349,15 +1357,17 @@ public enum ScriptActionType {
13491357 .arg ("Identifier" , ScriptActionArgumentType .TEXT )
13501358 .action (ctx -> {
13511359 String identifier = ctx .value ("Identifier" ).asText ();
1352- if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1353- if (menu .ownedBy (ctx .task ().context ().script ())) {
1354- menu .removeChild (identifier );
1360+ DFScript .MC .send (() -> {
1361+ if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1362+ if (menu .ownedBy (ctx .task ().context ().script ())) {
1363+ menu .removeChild (identifier );
1364+ } else {
1365+ OverlayManager .getInstance ().add ("Unable to remove element from menu! (Not owned by script)" );
1366+ }
13551367 } else {
1356- OverlayManager .getInstance ().add ("Unable to remove element from menu! (Not owned by script )" );
1368+ OverlayManager .getInstance ().add ("Unable to remove element from menu! (Unknown menu type )" );
13571369 }
1358- } else {
1359- OverlayManager .getInstance ().add ("Unable to remove element from menu! (Unknown menu type)" );
1360- }
1370+ });
13611371 })),
13621372
13631373 GET_MENU_TEXT_FIELD_VALUE (builder -> builder .name ("Get Menu Text Field Value" )
@@ -1397,20 +1407,22 @@ public enum ScriptActionType {
13971407 .action (ctx -> {
13981408 String identifier = ctx .value ("Identifier" ).asText ();
13991409
1400- if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1401- if (menu .ownedBy (ctx .task ().context ().script ())) {
1402- ScriptWidget w = menu .getWidget (identifier );
1403- if (w instanceof ScriptMenuTextField field ) {
1404- field .setText (ctx .value ("Value" ).asText ());
1410+ DFScript .MC .send (() -> {
1411+ if (io .github .techstreet .dfscript .DFScript .MC .currentScreen instanceof ScriptMenu menu ) {
1412+ if (menu .ownedBy (ctx .task ().context ().script ())) {
1413+ ScriptWidget w = menu .getWidget (identifier );
1414+ if (w instanceof ScriptMenuTextField field ) {
1415+ field .setText (ctx .value ("Value" ).asText ());
1416+ } else {
1417+ OverlayManager .getInstance ().add ("Unable to set text field value! (Unknown widget type)" );
1418+ }
14051419 } else {
1406- OverlayManager .getInstance ().add ("Unable to set text field value! (Unknown widget type )" );
1420+ OverlayManager .getInstance ().add ("Unable to set text field value! (Not owned by script )" );
14071421 }
14081422 } else {
1409- OverlayManager .getInstance ().add ("Unable to set text field value! (Not owned by script )" );
1423+ OverlayManager .getInstance ().add ("Unable to set text field value! (Unknown menu type )" );
14101424 }
1411- } else {
1412- OverlayManager .getInstance ().add ("Unable to set text field value! (Unknown menu type)" );
1413- }
1425+ });
14141426 })),
14151427
14161428 RANDOM_INT (builder -> builder .name ("Random Int" )
0 commit comments