Skip to content

Commit 970fc5f

Browse files
committed
Add test for Mana Spreaders in the Botania Mod Integration
1 parent 77df4d0 commit 970fc5f

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed

src/testMod/java/dan200/computercraft/gametest/core/TestAPI.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import dan200.computercraft.api.lua.LuaFunction;
1313
import dan200.computercraft.gametest.api.ComputerState;
1414
import dan200.computercraft.gametest.api.TestExtensionsKt;
15+
import dan200.computercraft.shared.computer.core.ServerContext;
16+
import de.srendi.advancedperipherals.common.util.LuaConverter;
1517
import net.minecraft.gametest.framework.GameTestSequence;
18+
import net.minecraftforge.server.ServerLifecycleHooks;
1619

1720
import java.util.Optional;
1821

@@ -80,4 +83,14 @@ public final void ok(Optional<String> marker) throws LuaException {
8083
public final void log(String message) {
8184
ComputerCraft.log.info("[Computer '{}'] {}", label, message);
8285
}
86+
87+
@LuaFunction
88+
public final Object getComputerPosition() {
89+
return ServerContext.get(ServerLifecycleHooks.getCurrentServer()).registry().getComputers().stream()
90+
.filter(computer -> computer.getLabel() != null && computer.getLabel().equals(label))
91+
.findFirst()
92+
.map(computer -> LuaConverter.posToObject(computer.getPosition()))
93+
.orElse(null);
94+
}
95+
8396
}

src/testMod/kotlin/de/srendi/advancedperipherals/test/ModIntegrTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ class ModIntegrTest {
1919
thenComputerOk();
2020
}
2121

22+
@GameTest
23+
fun botaniaSpreader(context: GameTestHelper) = context.sequence {
24+
thenComputerOk();
25+
}
26+
2227
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
--- Advanced Peripherals tests for the Botania integration on Mana Spreaders
3+
--- Covers `getMana`, `getMaxMana`, `getVariant`,
4+
--- `isEmpty`, `isFull`, `getBounding`
5+
---
6+
7+
-- TODO Add tests for hasLens and getLens in 1.20.1 AP versions
8+
9+
-- Test basic Mana Spreader that is empty and directed towards a Mana Pool
10+
test.eq("manaSpreader", peripheral.getType("left"), "Peripheral should be manaSpreader")
11+
spreader = peripheral.wrap("left")
12+
test.assert(spreader, "Peripheral not found")
13+
14+
test.eq(0, spreader.getMana(), "Mana should be 0")
15+
test.eq(1000, spreader.getMaxMana(), "Max mana should be 1000")
16+
test.eq("MANA", spreader.getVariant(), "Variant should be MANA")
17+
-- test.assert(spreader.isEmpty(), "Mana Spreader should be empty") TODO: method returns the wrong value currently
18+
test.assert(not spreader.isFull(), "Mana Spreader should not be full")
19+
20+
bounding = spreader.getBounding()
21+
computerPos = test.getComputerPosition()
22+
test.assert(bounding, "Spreader binding should be returned")
23+
test.assert(computerPos, "Computer position should be returned")
24+
25+
test.eq(computerPos.x + 1, bounding.x, "Bounding x should be set to Mana pool (+1 relative to computer)")
26+
test.eq(computerPos.y, bounding.y, "Bounding y should be set to Mana pool (same as computer)")
27+
test.eq(computerPos.z - 1, bounding.z, "Bounding z should be set to Mana pool (-1 relative to computer")
28+
29+
-- Test Gaia Mana Spreader that is full
30+
test.eq("manaSpreader", peripheral.getType("right"), "Peripheral should be manaSpreader")
31+
gaiaSpreader = peripheral.wrap("right")
32+
test.assert(gaiaSpreader, "Peripheral not found")
33+
34+
test.eq(6400, gaiaSpreader.getMana(), "Mana should be 6400")
35+
test.eq(6400, gaiaSpreader.getMaxMana(), "Max mana should be 6400")
36+
test.eq("GAIA", gaiaSpreader.getVariant(), "Variant should be GAIA")
37+
-- test.assert(not gaiaSpreader.isEmpty(), "Mana Spreader should not be empty") TODO: method returns the wrong value currently
38+
test.assert(gaiaSpreader.isFull(), "Mana Spreader should be full")
39+
40+
test.assert(not gaiaSpreader.getBounding(), "Mana Spreader should not be bound to anything")
41+
42+
-- Test Elven Mana Spreader that has 177 mana
43+
test.eq("manaSpreader", peripheral.getType("back"), "Peripheral should be manaSpreader")
44+
elvenSpreader = peripheral.wrap("back")
45+
test.assert(elvenSpreader, "Peripheral not found")
46+
47+
test.eq(177, elvenSpreader.getMana(), "Mana should be 177")
48+
test.eq(1000, elvenSpreader.getMaxMana(), "Max mana should be 1000")
49+
test.eq("ELVEN", elvenSpreader.getVariant(), "Variant should be ELVEN")
50+
-- test.assert(not elvenSpreader.isEmpty(), "Mana Spreader should not be empty") TODO: method returns the wrong value currently
51+
test.assert(not elvenSpreader.isFull(), "Mana Spreader should not be full")
52+
53+
test.assert(not elvenSpreader.getBounding(), "Mana Spreader should not be bound to anything")
54+
55+
-- Test Pulse Mana Spreader that is empty
56+
test.eq("manaSpreader", peripheral.getType("top"), "Peripheral should be manaSpreader")
57+
pulseSpreader = peripheral.wrap("top")
58+
test.assert(pulseSpreader, "Peripheral not found")
59+
60+
test.eq(0, pulseSpreader.getMana(), "Mana should be 0")
61+
test.eq(1000, pulseSpreader.getMaxMana(), "Max mana should be 1000")
62+
test.eq("REDSTONE", pulseSpreader.getVariant(), "Variant should be REDSTONE")
63+
-- test.assert(pulseSpreader.isEmpty(), "Mana Spreader should be empty") TODO: method returns the wrong value currently
64+
test.assert(not pulseSpreader.isFull(), "Mana Spreader should not be full")
65+
66+
test.assert(not pulseSpreader.getBounding(), "Mana Spreader should not be bound to anything")
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
DataVersion: 3120,
3+
size: [5, 5, 5],
4+
data: [
5+
{pos: [0, 0, 0], state: "minecraft:polished_andesite"},
6+
{pos: [0, 0, 1], state: "minecraft:polished_andesite"},
7+
{pos: [0, 0, 2], state: "minecraft:polished_andesite"},
8+
{pos: [0, 0, 3], state: "minecraft:polished_andesite"},
9+
{pos: [0, 0, 4], state: "minecraft:polished_andesite"},
10+
{pos: [1, 0, 0], state: "minecraft:polished_andesite"},
11+
{pos: [1, 0, 1], state: "minecraft:polished_andesite"},
12+
{pos: [1, 0, 2], state: "minecraft:polished_andesite"},
13+
{pos: [1, 0, 3], state: "minecraft:polished_andesite"},
14+
{pos: [1, 0, 4], state: "minecraft:polished_andesite"},
15+
{pos: [2, 0, 0], state: "minecraft:polished_andesite"},
16+
{pos: [2, 0, 1], state: "minecraft:polished_andesite"},
17+
{pos: [2, 0, 2], state: "minecraft:polished_andesite"},
18+
{pos: [2, 0, 3], state: "minecraft:polished_andesite"},
19+
{pos: [2, 0, 4], state: "minecraft:polished_andesite"},
20+
{pos: [3, 0, 0], state: "minecraft:polished_andesite"},
21+
{pos: [3, 0, 1], state: "minecraft:polished_andesite"},
22+
{pos: [3, 0, 2], state: "minecraft:polished_andesite"},
23+
{pos: [3, 0, 3], state: "minecraft:polished_andesite"},
24+
{pos: [3, 0, 4], state: "minecraft:polished_andesite"},
25+
{pos: [4, 0, 0], state: "minecraft:polished_andesite"},
26+
{pos: [4, 0, 1], state: "minecraft:polished_andesite"},
27+
{pos: [4, 0, 2], state: "minecraft:polished_andesite"},
28+
{pos: [4, 0, 3], state: "minecraft:polished_andesite"},
29+
{pos: [4, 0, 4], state: "minecraft:polished_andesite"},
30+
{pos: [0, 1, 0], state: "minecraft:air"},
31+
{pos: [0, 1, 1], state: "minecraft:air"},
32+
{pos: [0, 1, 2], state: "minecraft:air"},
33+
{pos: [0, 1, 3], state: "minecraft:air"},
34+
{pos: [0, 1, 4], state: "minecraft:air"},
35+
{pos: [1, 1, 0], state: "minecraft:air"},
36+
{pos: [1, 1, 1], state: "minecraft:air"},
37+
{pos: [1, 1, 2], state: "minecraft:air"},
38+
{pos: [1, 1, 3], state: "minecraft:air"},
39+
{pos: [1, 1, 4], state: "minecraft:air"},
40+
{pos: [2, 1, 0], state: "minecraft:air"},
41+
{pos: [2, 1, 1], state: "botania:mana_spreader{has_scaffolding:false,waterlogged:false}", nbt: {ForgeCaps: {}, Items: [], canShootBurst: 1b, forceClientBindingX: 10, forceClientBindingY: 60, forceClientBindingZ: -9, id: "botania:mana_spreader", inputKey: "", lastPingbackX: 0.0d, lastPingbackY: -2.147483648E9d, lastPingbackZ: 0.0d, mana: 0, mapmakerOverrideEnabled: 0b, mmForcedColor: 2162464, mmForcedGravity: 0.0f, mmForcedManaLossPerTick: 4.0f, mmForcedManaPayload: 160, mmForcedTicksBeforeManaLoss: 60, mmForcedVelocityMultiplier: 1.0f, outputKey: "", paddingColor: -1, pingbackTicks: 0, requestUpdate: 0b, rotationX: 180.0f, rotationY: -14.036243f, uuid: [I; -1335544995, 1721978540, -1824636534, -1356366853]}},
42+
{pos: [2, 1, 2], state: "computercraft:computer_advanced{facing:west,state:blinking}", nbt: {ComputerId: 0, ForgeCaps: {}, Label: "modintegrtest.botaniaspreader", On: 1b, id: "computercraft:computer_advanced"}},
43+
{pos: [2, 1, 3], state: "botania:gaia_spreader{has_scaffolding:false,waterlogged:false}", nbt: {ForgeCaps: {}, Items: [], canShootBurst: 1b, forceClientBindingX: 0, forceClientBindingY: -2147483648, forceClientBindingZ: 0, id: "botania:mana_spreader", inputKey: "", lastPingbackX: 0.0d, lastPingbackY: -2.147483648E9d, lastPingbackZ: 0.0d, mana: 6400, mapmakerOverrideEnabled: 0b, mmForcedColor: 2162464, mmForcedGravity: 0.0f, mmForcedManaLossPerTick: 4.0f, mmForcedManaPayload: 160, mmForcedTicksBeforeManaLoss: 60, mmForcedVelocityMultiplier: 1.0f, outputKey: "", paddingColor: -1, pingbackTicks: 0, requestUpdate: 0b, rotationX: 0.0f, rotationY: 90.0f, uuid: [I; 488019582, 1505248039, -1662086631, -1403515204]}},
44+
{pos: [2, 1, 4], state: "minecraft:air"},
45+
{pos: [3, 1, 0], state: "minecraft:air"},
46+
{pos: [3, 1, 1], state: "botania:mana_pool{color:none,waterlogged:false}", nbt: {ForgeCaps: {}, canAccept: 1b, canSpare: 1b, id: "botania:mana_pool", inputKey: "", mana: 0, manaCap: 1000000, outputKey: "", outputting: 0b}},
47+
{pos: [3, 1, 2], state: "botania:elven_spreader{has_scaffolding:false,waterlogged:false}", nbt: {ForgeCaps: {}, Items: [], canShootBurst: 1b, forceClientBindingX: 0, forceClientBindingY: -2147483648, forceClientBindingZ: 0, id: "botania:mana_spreader", inputKey: "", lastPingbackX: 0.0d, lastPingbackY: -2.147483648E9d, lastPingbackZ: 0.0d, mana: 177, mapmakerOverrideEnabled: 0b, mmForcedColor: 2162464, mmForcedGravity: 0.0f, mmForcedManaLossPerTick: 4.0f, mmForcedManaPayload: 160, mmForcedTicksBeforeManaLoss: 60, mmForcedVelocityMultiplier: 1.0f, outputKey: "", paddingColor: -1, pingbackTicks: 0, requestUpdate: 0b, rotationX: 0.0f, rotationY: 90.0f, uuid: [I; -360645062, -1521991436, -1469095441, -381296848]}},
48+
{pos: [3, 1, 3], state: "minecraft:air"},
49+
{pos: [3, 1, 4], state: "minecraft:air"},
50+
{pos: [4, 1, 0], state: "minecraft:air"},
51+
{pos: [4, 1, 1], state: "minecraft:air"},
52+
{pos: [4, 1, 2], state: "minecraft:air"},
53+
{pos: [4, 1, 3], state: "minecraft:air"},
54+
{pos: [4, 1, 4], state: "minecraft:air"},
55+
{pos: [0, 2, 0], state: "minecraft:air"},
56+
{pos: [0, 2, 1], state: "minecraft:air"},
57+
{pos: [0, 2, 2], state: "minecraft:air"},
58+
{pos: [0, 2, 3], state: "minecraft:air"},
59+
{pos: [0, 2, 4], state: "minecraft:air"},
60+
{pos: [1, 2, 0], state: "minecraft:air"},
61+
{pos: [1, 2, 1], state: "minecraft:air"},
62+
{pos: [1, 2, 2], state: "minecraft:air"},
63+
{pos: [1, 2, 3], state: "minecraft:air"},
64+
{pos: [1, 2, 4], state: "minecraft:air"},
65+
{pos: [2, 2, 0], state: "minecraft:air"},
66+
{pos: [2, 2, 1], state: "minecraft:air"},
67+
{pos: [2, 2, 2], state: "botania:redstone_spreader{has_scaffolding:false,waterlogged:false}", nbt: {ForgeCaps: {}, Items: [], canShootBurst: 1b, forceClientBindingX: 0, forceClientBindingY: -2147483648, forceClientBindingZ: 0, id: "botania:mana_spreader", inputKey: "", lastPingbackX: 0.0d, lastPingbackY: -2.147483648E9d, lastPingbackZ: 0.0d, mana: 0, mapmakerOverrideEnabled: 0b, mmForcedColor: 2162464, mmForcedGravity: 0.0f, mmForcedManaLossPerTick: 4.0f, mmForcedManaPayload: 160, mmForcedTicksBeforeManaLoss: 60, mmForcedVelocityMultiplier: 1.0f, outputKey: "", paddingColor: -1, pingbackTicks: 0, requestUpdate: 0b, rotationX: 0.0f, rotationY: 90.0f, uuid: [I; 758151075, -302429323, -1148181277, 1481371264]}},
68+
{pos: [2, 2, 3], state: "minecraft:air"},
69+
{pos: [2, 2, 4], state: "minecraft:air"},
70+
{pos: [3, 2, 0], state: "minecraft:air"},
71+
{pos: [3, 2, 1], state: "minecraft:air"},
72+
{pos: [3, 2, 2], state: "minecraft:air"},
73+
{pos: [3, 2, 3], state: "minecraft:air"},
74+
{pos: [3, 2, 4], state: "minecraft:air"},
75+
{pos: [4, 2, 0], state: "minecraft:air"},
76+
{pos: [4, 2, 1], state: "minecraft:air"},
77+
{pos: [4, 2, 2], state: "minecraft:air"},
78+
{pos: [4, 2, 3], state: "minecraft:air"},
79+
{pos: [4, 2, 4], state: "minecraft:air"},
80+
{pos: [0, 3, 0], state: "minecraft:air"},
81+
{pos: [0, 3, 1], state: "minecraft:air"},
82+
{pos: [0, 3, 2], state: "minecraft:air"},
83+
{pos: [0, 3, 3], state: "minecraft:air"},
84+
{pos: [0, 3, 4], state: "minecraft:air"},
85+
{pos: [1, 3, 0], state: "minecraft:air"},
86+
{pos: [1, 3, 1], state: "minecraft:air"},
87+
{pos: [1, 3, 2], state: "minecraft:air"},
88+
{pos: [1, 3, 3], state: "minecraft:air"},
89+
{pos: [1, 3, 4], state: "minecraft:air"},
90+
{pos: [2, 3, 0], state: "minecraft:air"},
91+
{pos: [2, 3, 1], state: "minecraft:air"},
92+
{pos: [2, 3, 2], state: "minecraft:air"},
93+
{pos: [2, 3, 3], state: "minecraft:air"},
94+
{pos: [2, 3, 4], state: "minecraft:air"},
95+
{pos: [3, 3, 0], state: "minecraft:air"},
96+
{pos: [3, 3, 1], state: "minecraft:air"},
97+
{pos: [3, 3, 2], state: "minecraft:air"},
98+
{pos: [3, 3, 3], state: "minecraft:air"},
99+
{pos: [3, 3, 4], state: "minecraft:air"},
100+
{pos: [4, 3, 0], state: "minecraft:air"},
101+
{pos: [4, 3, 1], state: "minecraft:air"},
102+
{pos: [4, 3, 2], state: "minecraft:air"},
103+
{pos: [4, 3, 3], state: "minecraft:air"},
104+
{pos: [4, 3, 4], state: "minecraft:air"},
105+
{pos: [0, 4, 0], state: "minecraft:air"},
106+
{pos: [0, 4, 1], state: "minecraft:air"},
107+
{pos: [0, 4, 2], state: "minecraft:air"},
108+
{pos: [0, 4, 3], state: "minecraft:air"},
109+
{pos: [0, 4, 4], state: "minecraft:air"},
110+
{pos: [1, 4, 0], state: "minecraft:air"},
111+
{pos: [1, 4, 1], state: "minecraft:air"},
112+
{pos: [1, 4, 2], state: "minecraft:air"},
113+
{pos: [1, 4, 3], state: "minecraft:air"},
114+
{pos: [1, 4, 4], state: "minecraft:air"},
115+
{pos: [2, 4, 0], state: "minecraft:air"},
116+
{pos: [2, 4, 1], state: "minecraft:air"},
117+
{pos: [2, 4, 2], state: "minecraft:air"},
118+
{pos: [2, 4, 3], state: "minecraft:air"},
119+
{pos: [2, 4, 4], state: "minecraft:air"},
120+
{pos: [3, 4, 0], state: "minecraft:air"},
121+
{pos: [3, 4, 1], state: "minecraft:air"},
122+
{pos: [3, 4, 2], state: "minecraft:air"},
123+
{pos: [3, 4, 3], state: "minecraft:air"},
124+
{pos: [3, 4, 4], state: "minecraft:air"},
125+
{pos: [4, 4, 0], state: "minecraft:air"},
126+
{pos: [4, 4, 1], state: "minecraft:air"},
127+
{pos: [4, 4, 2], state: "minecraft:air"},
128+
{pos: [4, 4, 3], state: "minecraft:air"},
129+
{pos: [4, 4, 4], state: "minecraft:air"}
130+
],
131+
entities: [],
132+
palette: [
133+
"minecraft:polished_andesite",
134+
"minecraft:air",
135+
"botania:mana_spreader{has_scaffolding:false,waterlogged:false}",
136+
"computercraft:computer_advanced{facing:west,state:blinking}",
137+
"botania:gaia_spreader{has_scaffolding:false,waterlogged:false}",
138+
"botania:mana_pool{color:none,waterlogged:false}",
139+
"botania:elven_spreader{has_scaffolding:false,waterlogged:false}",
140+
"botania:redstone_spreader{has_scaffolding:false,waterlogged:false}"
141+
]
142+
}

0 commit comments

Comments
 (0)