How to get the block id(python code)
There are two functions to get the block id of a block:
1. agent.inspect(kind: AgentInspection, direction: SixDirection): number;
kind: AgentInspection.BLOCK or AgentInspection.Data
however, at present this function can only get the type of a block. for example, when inspecting a mossy stone block, it return stone, not mossy stone.
and inspect(AgentInspection.DATA,direction) always return -1 in my environment(win10)
2. blocks.test_for_block(block,pos):
Test to see if a block at the chosen position is a certain type. we need to traverse all the possibilities before getting the exact id of the block.
one solution, the function below can inspect the block under the player, using above two functions inspect and test_for_block:
'''
def inspect_block_at_foot(self):
agent.teleport_to_player()
what = agent.inspect(AgentInspection.BLOCK, DOWN)
for i in range(1, 16):
detail = 65536 * i + what
if blocks.test_for_block(detail, pos(0, -1, 0)):
return detail
return what
'''
2
-
more common one:
def inspect_block_at_pos(position):agent.teleport(position.add(pos(0, 1, 0)), WEST)what = agent.inspect(AgentInspection.BLOCK, DOWN)for i in range(1, 16):detail = 65536 * i + whatif blocks.test_for_block(detail, pos(0, -1, 0)):return detailreturn what0
Please sign in to leave a comment.
Comments
1 comment