8000 Workbench peripheral · neumond/python-computer-craft@1930ae8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1930ae8

Browse files
committed
Workbench peripheral
1 parent dd865f2 commit 1930ae8

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

computercraft/subapis/peripheral.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from .base import BaseSubAPI
66
from .mixins import TermMixin, TermTarget
7+
from .turtle import craft_result
78
from ..lua import LuaNum, lua_args
89
from ..rproc import (
910
boolean, nil, integer, string, option_integer, option_string,
@@ -248,13 +249,19 @@ async def runCommand(self):
248249
return try_result(await self._send('runCommand'))
249250

250251

252+
class CCWorkbench(BasePeripheral):
253+
async def craft(self, quantity: int = 64) -> bool:
254+
return craft_result(await self._send('craft', quantity))
255+
256+
251257
TYPE_MAP = {
252258
'drive': CCDrive,
253259
'monitor': CCMonitor,
254260
'computer': CCComputer,
255261
'printer': CCPrinter,
256262
'speaker': CCSpeaker,
257263
'command': CCCommandBlock,
264+
'workbench': CCWorkbench,
258265
}
259266

260267

computercraft/subapis/turtle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def always_true(r):
5555

5656

5757
class TurtleAPI(BaseSubAPI):
58-
async def craft(self, quantity: int = 1) -> bool:
58+
async def craft(self, quantity: int = 64) -> bool:
5959
return craft_result(await self._send('craft', quantity))
6060

6161
async def forward(self) -> bool:

testmod.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,27 +2077,34 @@ async def test_turtle(api):
20772077
assert await api.turtle.dropUp() is True
20782078
assert await api.turtle.getItemCount() == 0
20792079

2080-
await step(
2081-
api,
2082-
'Clean inventory of turtle\n'
2083-
'Put crafting table into slot 1\n'
2084-
'Put 8 cobblestones into slot 2',
2085-
)
2080+
async def craft1():
2081+
return await api.turtle.craft()
20862082

2083+
async def craft2():
2084+
c = await api.peripheral.wrap('right')
2085+
return await c.craft()
2086+
2087+
await step(api, 'Put crafting table into slot 1')
20872088
assert await api.turtle.select(1) is None
20882089
assert await api.turtle.equipRight() is None
20892090

2090-
assert await api.turtle.select(2) is None
2091-
assert await api.turtle.craft() is False
2092-
for idx in [1, 3, 5, 7, 9, 10, 11]:
2093-
assert await api.turtle.transferTo(idx, 1)
2094-
assert await api.turtle.craft() is True
2095-
2096-
assert await api.turtle.select(1) is None
2097-
assert await api.turtle.getItemDetail(1) == {
2098-
'count': 1,
2099-
'name': 'minecraft:furnace',
2100-
}
2091+
for craft_fn in craft1, craft2:
2092+
await step(
2093+
api,
2094+
'Clean inventory of turtle\n'
2095+
'Put 8 cobblestones into slot 1',
2096+
)
2097+
2098+
assert await api.turtle.select(1) is None
2099+
assert await craft_fn() is False
2100+
for idx in [2, 3, 5, 7, 9, 10, 11]:
2101+
assert await api.turtle.transferTo(idx, 1)
2102+
assert await craft_fn() is True
2103+
assert await craft_fn() is False
2104+
assert await api.turtle.getItemDetail() == {
2105+
'count': 1,
2106+
'name': 'minecraft:furnace',
2107+
}
21012108

21022109
await api.print('Test finished successfully')
21032110

0 commit comments

Comments
 (0)
0