|
1 | 1 | package org.cyclops.integratedscripting.gametest; |
2 | 2 |
|
| 3 | +import com.google.common.collect.Lists; |
3 | 4 | import net.minecraft.core.BlockPos; |
4 | 5 | import net.minecraft.gametest.framework.GameTest; |
5 | 6 | import net.minecraft.gametest.framework.GameTestHelper; |
| 7 | +import net.minecraft.network.chat.Component; |
6 | 8 | import net.minecraft.world.item.ItemStack; |
7 | 9 | import net.neoforged.neoforge.gametest.GameTestHolder; |
8 | 10 | import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; |
@@ -81,4 +83,35 @@ public void testScriptsDisplayScriptApplied(GameTestHelper helper) { |
81 | 83 | }); |
82 | 84 | } |
83 | 85 |
|
| 86 | + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
| 87 | + public void testScriptsDisplayScriptInfiniteLoop(GameTestHelper helper) { |
| 88 | + GameTestHelpersIntegratedScripting.NetworkPositions positions = createBasicNetwork(helper, POS); |
| 89 | + |
| 90 | + // Write script |
| 91 | + ScriptingNetworkHelpers.getScriptingData().setScript(positions.diskId(), Path.of("script0.js"), "function oops() {\n" + |
| 92 | + " while (true) {}\n" + |
| 93 | + "}", IScriptingData.ChangeLocation.MEMORY); |
| 94 | + |
| 95 | + // Create variable from script |
| 96 | + ItemStack variableScript = createVariableForScript(helper.getLevel(), positions.diskId(), Path.of("script0.js"), "abc"); |
| 97 | + |
| 98 | + // Insert all variables into the variable store |
| 99 | + positions.variableStore().getInventory().setItem(0, variableScript); |
| 100 | + |
| 101 | + // Create variable card for applying the function |
| 102 | + ItemStack variableAdded = createVariableForOperator(helper.getLevel(), Operators.OPERATOR_APPLY_0, new int[]{ |
| 103 | + getVariableFacade(helper.getLevel(), variableScript).getId() |
| 104 | + }); |
| 105 | + |
| 106 | + // Place variable in display |
| 107 | + Pair<PartTypePanelDisplay, PartTypePanelDisplay.State> partAndState = placeVariableInDisplayPanel(helper.getLevel(), positions.displayPanel(), variableAdded); |
| 108 | + |
| 109 | + helper.succeedWhen(() -> { |
| 110 | + helper.assertValueEqual(partAndState.getRight().getGlobalErrors(), Lists.newArrayList( |
| 111 | + Component.translatable("script.integratedscripting.error.member_not_in_network", positions.diskId(), "abc", "script0.js"), |
| 112 | + Component.translatable("script.integratedscripting.error.member_not_in_network", positions.diskId(), "abc", "script0.js") |
| 113 | + ), "Display panel errors do not match"); |
| 114 | + }); |
| 115 | + } |
| 116 | + |
84 | 117 | } |
0 commit comments