Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mob pick #1362

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion droidlet/interpreter/craftassist/mc_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, speaker, logical_form_memid, agent_memory, memid=None, low_le
self.get_locs_from_entity = low_level_data["get_locs_from_entity"]
self.special_shape_functions = low_level_data["special_shape_functions"]
self.color_bid_map = low_level_data["color_bid_map"]
self.allow_clarification = low_level_data["allow_clarification"]
self.allow_clarification = low_level_data.get("allow_clarification", False)
# These come from agent's perception
self.get_all_holes_fn = low_level_data["get_all_holes_fn"]
self.workspace_memory_prio = ["Mob", "BlockObject"]
Expand Down
25 changes: 25 additions & 0 deletions droidlet/lowlevel/minecraft/pyworld/fake_mobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def __init__(self, opts, start_pos=None, start_look=(0.0, 0.0)):
self.entityId = str(np.random.randint(0, 100000))
self.mobType = opts.mobType
self.agent_built = False
self.inventory = set()
self.pick_prob = getattr(opts, "pick_prob", 0.0)
self.drop_prob = getattr(opts, "drop_prob", 0.0)
self.pick_range = getattr(opts, "pick_range", 0.0)

def add_to_world(self, world):
self.world = world
Expand Down Expand Up @@ -100,6 +104,27 @@ def new_direction(self):
self.look = (yaw, 0.0)

def step(self):
# if mob is carrying something, maybe drop:
if np.random.rand() < self.drop_prob and len(self.inventory) > 0:
eid = self.inventory.pop()
dropped = self.world.player_pick_drop_items(self.entityId, [eid], action="drop")
if dropped == 0: # world didn't drop it, add back to inventory
self.inventory.add(eid)

# if mob can pick things, and if something is nearby, pick it
if np.random.rand() < self.pick_prob:
pickable_items = self.world.get_items()
for i in pickable_items:
if i["holder_entityId"] == -1: # on ground
ix, iy, iz = i["x"], i["y"], i["z"]
x, y, z = self.pos
if (x - ix) ** 2 + (y - iy) ** 2 + (z - iz) ** 2 < self.pick_range**2:
picked = self.world.player_pick_drop_items(
self.entityId, [i["entityId"]], action="pick"
)
if picked > 0:
self.inventory.add(i["entityId"])

# check if falling:
x, y, z = self.world.to_npy_coords(self.pos)
fy = min(max(int(np.floor(y)), 0), self.world.blocks.shape[1])
Expand Down