arpruss / raspberryjammod

Raspberry Jam Mod - a Mod Forge Minecraft mod implementing most of Raspberry Juice/Pi API
http://www.instructables.com/id/Python-coding-for-Minecraft/
Other
355 stars 95 forks source link

mc.events.pollBlockHits() always returns empty array #7

Closed BlackstoneEngineering closed 8 years ago

BlackstoneEngineering commented 8 years ago

Problem

The event.pollBlockHits() function always returns an empty array. This is either a bug or a feature to be implemented, not sure which. The setup tested on is v1.8 using Forge, as directed in the instructable post.

Example

I run the following script as I smash blocks

from mc import *
import time

mc = Minecraft()
mc.postToChat("Running Scratch2!")

while True:
    hits = mc.events.pollBlockHits()
    mc.postToChat(hits)
    time.sleep(5)

I see the 'Running Scratch2!' message, but the array returned from pollBlockHits is always empty [ ].

arpruss commented 8 years ago

As per the Raspberry Pi Minecraft API, pollBlockHits() by default detects only right clicks with a sword. Are you right clicking and do you have a sword in hand? There are options to control this behavior. See symmetry.py.

BlackstoneEngineering commented 8 years ago

Ah, got it, I had to equip a sword to make it trigger, it would not work bare handed.

While I have your attention I would like to ask your expertise on something. I have managed to trigger in game events via real world stimuli by using the python script to poll an external server and create blocks in game when. Now I am trying to have events in game trigger external events. I was thinking of having redstone trigger a send to the external server. Currently I have only found the events.pollBlockHits() function, is there a better way to use triggers in game via the python scripts? Like some way to hook up to redstone switches ... etc?

arpruss commented 8 years ago

Three options:

  1. Polling with mc.getBlock() and mc.player.getPos() gets you useful information.
  2. Call: mc.conn.send("events.setting","restrict_to_sword",0) mc.conn.send("events.setting","detect_left_click",1) and then pollBlockHits() will capture both left and right clicks, regardless of what you're holding.
  3. Use a commandblock that launches a python script on top of your main script: "/apy scriptname.py" (when you launch a script with /py, it stops all current scripts; /apy doesn't do that). Then communicate between the scripts using sockets or something else.

Methods 2 and 3 will only work on RaspberryJamMod, not on the official Pi API.

BlackstoneEngineering commented 8 years ago

Awesome, I'm going to give this a try, thank you!