Skip to content

Commit 82cb854

Browse files
committed
Add game test for using item methods
1 parent 29051aa commit 82cb854

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/main/java/org/cyclops/integratedscripting/gametest/GameTestsScripts.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
import net.minecraft.gametest.framework.GameTestHelper;
77
import net.minecraft.network.chat.Component;
88
import net.minecraft.world.item.ItemStack;
9+
import net.minecraft.world.item.Items;
910
import net.neoforged.neoforge.gametest.GameTestHolder;
1011
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
1112
import org.apache.commons.lang3.tuple.Pair;
1213
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;
1316
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeInteger;
1417
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes;
1518
import org.cyclops.integrateddynamics.part.PartTypePanelDisplay;
@@ -83,6 +86,37 @@ public void testScriptsDisplayScriptApplied(GameTestHelper helper) {
8386
});
8487
}
8588

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+
86120
@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
87121
public void testScriptsDisplayScriptInfiniteLoop(GameTestHelper helper) {
88122
GameTestHelpersIntegratedScripting.NetworkPositions positions = createBasicNetwork(helper, POS);

0 commit comments

Comments
 (0)