Skip to content

Commit 26e7966

Browse files
committed
Do not swing arm when right-clicking entity
1 parent d009b13 commit 26e7966

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

spockbot/plugins/helpers/interact.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,18 @@ def use_entity(self, entity, cursor_pos=None,
196196
"""
197197
if self.auto_look:
198198
self.look_at(Vector3(entity)) # TODO look at cursor_pos
199-
if cursor_pos is not None:
199+
200+
if cursor_pos is not None and action == constants.INTERACT_ENTITY:
200201
action = constants.INTERACT_ENTITY_AT
202+
201203
packet = {'target': entity.eid, 'action': action}
202204
if action == constants.INTERACT_ENTITY_AT:
203205
packet['target_x'] = cursor_pos.x
204206
packet['target_y'] = cursor_pos.y
205207
packet['target_z'] = cursor_pos.z
206208
self.net.push_packet('PLAY>Use Entity', packet)
207-
if self.auto_swing:
209+
210+
if self.auto_swing and action == constants.ATTACK_ENTITY:
208211
self.swing_arm()
209212

210213
def attack_entity(self, entity):

tests/plugins/helpers/test_interact.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,22 @@ def test_activate_item(self):
115115
# TODO deactivate_item
116116

117117
def test_entity(self):
118+
# interact entity should not swing arm
118119
entity = DataDict(eid=234, x=2, y=2 + constants.PLAYER_EYE_HEIGHT, z=4)
119-
120120
self.plug.use_entity(entity)
121121
self.assertAlmostEqual(ClientInfoMock.position.yaw, -45)
122122
self.assertAlmostEqual(ClientInfoMock.position.pitch, 0)
123-
self.assertEqual(NetMock.datas[-2].action, constants.INTERACT_ENTITY)
124-
self.assertEqual(NetMock.datas[-2].target, 234)
123+
self.assertEqual(NetMock.datas[-1].action, constants.INTERACT_ENTITY)
124+
self.assertEqual(NetMock.datas[-1].target, 234)
125+
self.assertEqual(len(NetMock.datas), 1)
126+
127+
# attack entity should swing arm
128+
entity = DataDict(eid=235, x=2, y=2 + constants.PLAYER_EYE_HEIGHT, z=4)
129+
self.plug.use_entity(entity, action=constants.ATTACK_ENTITY)
130+
self.assertAlmostEqual(ClientInfoMock.position.yaw, -45)
131+
self.assertAlmostEqual(ClientInfoMock.position.pitch, 0)
132+
self.assertEqual(NetMock.datas[-2].action, constants.ATTACK_ENTITY)
133+
self.assertEqual(NetMock.datas[-2].target, 235)
125134
self.assertEqual(NetMock.idents[-1], 'PLAY>Animation')
126135

127136
self.plug.auto_look = False

0 commit comments

Comments
 (0)