|
6 | 6 | import net.minecraft.gametest.framework.GameTestHelper; |
7 | 7 | import net.minecraft.network.chat.Component; |
8 | 8 | import net.minecraft.world.item.ItemStack; |
| 9 | +import net.minecraft.world.item.Items; |
9 | 10 | import net.neoforged.neoforge.gametest.GameTestHolder; |
10 | 11 | import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; |
11 | 12 | import org.apache.commons.lang3.tuple.Pair; |
12 | 13 | import org.cyclops.integrateddynamics.core.evaluate.operator.Operators; |
| 14 | +import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack; |
| 15 | +import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeBoolean; |
13 | 16 | import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeInteger; |
14 | 17 | import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes; |
15 | 18 | import org.cyclops.integrateddynamics.part.PartTypePanelDisplay; |
@@ -83,6 +86,37 @@ public void testScriptsDisplayScriptApplied(GameTestHelper helper) { |
83 | 86 | }); |
84 | 87 | } |
85 | 88 |
|
| 89 | + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
| 90 | + public void testScriptsDisplayScriptOnItem(GameTestHelper helper) { |
| 91 | + GameTestHelpersIntegratedScripting.NetworkPositions positions = createBasicNetwork(helper, POS); |
| 92 | + |
| 93 | + // Write script |
| 94 | + ScriptingNetworkHelpers.getScriptingData().setScript(positions.diskId(), Path.of("script0.js"), "function abc(item) { return item.isStackable() && item.size() >= 16; }", IScriptingData.ChangeLocation.MEMORY); |
| 95 | + |
| 96 | + // Create variable from script |
| 97 | + ItemStack variableScript = createVariableForScript(helper.getLevel(), positions.diskId(), Path.of("script0.js"), "abc"); |
| 98 | + |
| 99 | + // Create constants as input to the script's function |
| 100 | + ItemStack variableConst1 = createVariableForValue(helper.getLevel(), ValueTypes.OBJECT_ITEMSTACK, ValueObjectTypeItemStack.ValueItemStack.of(new ItemStack(Items.APPLE, 32))); |
| 101 | + |
| 102 | + // Insert all variables into the variable store |
| 103 | + positions.variableStore().getInventory().setItem(0, variableScript); |
| 104 | + positions.variableStore().getInventory().setItem(1, variableConst1); |
| 105 | + |
| 106 | + // Create variable card for applying the function |
| 107 | + ItemStack variableApplied = createVariableForOperator(helper.getLevel(), Operators.OPERATOR_APPLY, new int[]{ |
| 108 | + getVariableFacade(helper.getLevel(), variableScript).getId(), |
| 109 | + getVariableFacade(helper.getLevel(), variableConst1).getId(), |
| 110 | + }); |
| 111 | + |
| 112 | + // Place variable in display |
| 113 | + Pair<PartTypePanelDisplay, PartTypePanelDisplay.State> partAndState = placeVariableInDisplayPanel(helper.getLevel(), positions.displayPanel(), variableApplied); |
| 114 | + |
| 115 | + helper.succeedWhen(() -> { |
| 116 | + assertValueEqual(partAndState.getRight().getDisplayValue(), ValueTypeBoolean.ValueBoolean.of(true)); |
| 117 | + }); |
| 118 | + } |
| 119 | + |
86 | 120 | @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
87 | 121 | public void testScriptsDisplayScriptInfiniteLoop(GameTestHelper helper) { |
88 | 122 | GameTestHelpersIntegratedScripting.NetworkPositions positions = createBasicNetwork(helper, POS); |
|
0 commit comments