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

Explore Interactive Scenes #39

Closed
acs opened this issue Apr 21, 2020 · 14 comments
Closed

Explore Interactive Scenes #39

acs opened this issue Apr 21, 2020 · 14 comments
Labels
Framework Work in the framework

Comments

@acs
Copy link
Contributor

acs commented Apr 21, 2020

Events in Minecrafts, like hitting a block, can be collected from the Python API. So when the player hits a block (for example a button), the scene could change and show/hide Things, for example.

@acs acs added this to To do in McThings v0.30.0 via automation May 11, 2020
@acs acs added the Framework Work in the framework label May 14, 2020
@acs acs moved this from To do to In progress in McThings v0.30.0 May 14, 2020
@acs acs moved this from In progress to To do in McThings v0.30.0 May 15, 2020
@acs acs moved this from To do to In progress in McThings v0.30.0 May 20, 2020
@acs
Copy link
Contributor Author

acs commented May 20, 2020

Taking a look to the API: https://www.stuffaboutcode.com/p/minecraft-api-reference.html

event.py
Class BlockEvent - definition of a block event, specifically what event, what block and what player

 Minecraft.events
.pollBlockHits()
"Block Hits (Only triggered by sword) => [BlockEvent]"
#get block event hits that have occured since the last time the function was run
blockEvents = mc.events.pollBlockHits()
for blockEvent in blockEvents:
    print blockEvent

.clearAll()
"Clear all old events"
#clear all events that have happened since the events where last got
mc.events.clearAll()

So the interactivity is easy: you need a sword? and when you hit a block, you get the block data that was hit. The block could be a button for example, or a lever.

The already interactive blocks in minecraft are: https://minecraft.fandom.com/wiki/Category:Interactive_blocks But we can do addiitonal things when collecting the events.

@acs
Copy link
Contributor Author

acs commented May 20, 2020

Next steps:

  • Check the pollBlockHits data
  • Add interactivity to some basic scene

@acs
Copy link
Contributor Author

acs commented May 20, 2020

In the extended API in the Rasperry Juice version, there is an API call to collect the chat messages. With it, you can implement a bot that read the chat messages and do things based on them. It could be pretty interesting also.

But I am not sure that this endpoint is implemented in the Forge mod or in Minetest:

.pollChatPosts()
"Chat posts => [ChatEvent]"
Available on RaspberryJuice
#get chat post events (messages) since the last time the function was run
chatEvents = mc.events.pollChatPosts()
for chatEvent in chatEvents:
    print chatEvents

https://github.com/arpruss/raspberryjammod ... it seems it takes the chat events also

And in Minetest: https://github.com/arpruss/raspberryjammod-minetest it is also implemented

@acs
Copy link
Contributor Author

acs commented May 21, 2020

After thinking a bit about what can be done here. I have decided to build an interactive scene showing the capabilities of McThings:

  • An action will build the next Thing in a Scene
  • Other action will unbuilt it
  • Other action will change the block used
  • Other actions will let you make the Thing smaller or bigger
  • Other actionss will let you build the Things closer or further

This is just an stating point from which to evolve.

The basic scene will have two Things to play with them. Let's call the Scene the interactive scene.

Let's use two pyramids.

Let's take a look to the official blocks in the API: https://www.stuffaboutcode.com/p/minecraft-api-reference.html There are not interactive blocks. Ideally. I would like to have the lever and the button and *pressure plates.

https://minecraft.gamepedia.com/Button
https://minecraft.gamepedia.com/Lever
https://minecraft.gamepedia.com/Pressure_Plate

None of them are available in the API, but let's see if we can create them just using Block(block_id).

@acs
Copy link
Contributor Author

acs commented May 21, 2020

Let's take a look to the available blocks using the BlockGallery Thing in 1.12.2 ....

https://www.minecraftinfo.com/idlist.htm

  • Lever: 69
  • Pressure plate: 70
  • Buttom: 77

Let's confirm we have all of them available.

Scene.server.setBlock(
  self.position.x, self.position.y, self.position.z+10, 
  mcpi.block.Block(69)
)
Scene.server.setBlock(
  self.position.x, self.position.y, self.position.z+10, 
  mcpi.block.Block(70)
)
Scene.server.setBlock(
  self.position.x, self.position.y, self.position.z+10, 
  mcpi.block.Block(77)
)

@acs
Copy link
Contributor Author

acs commented May 21, 2020

Ok, to generate hits you need to have a sword and right click on a block (left click hits with the sword to do damage, right click is the one generating events).

And and event is something like:

BlockEvent(BlockEvent.HIT, 43, 1, 817, 5, 57)

Each hit generates 3 events (Up, down, up):

Screenshot from 2020-05-21 08-06-02

And if you leave the button pressed, you get lots of events:

Screenshot from 2020-05-21 08-08-01

@acs
Copy link
Contributor Author

acs commented May 21, 2020

Ok, so the path is clear to start buiding interactive scenes. In my next session I will implement it!

@acs
Copy link
Contributor Author

acs commented May 21, 2020

The idea is evolving. The scene will have a platform in the sky from which you can see the full scene. And from it, you can build and unbuild things, and change the block used in the construction. Let's see if it is possible to implement in a reasonable way.

@acs
Copy link
Contributor Author

acs commented May 22, 2020

Mostly done:

Screenshot from 2020-05-22 08-31-24

Right hitting with the sword in the glass bar build the next item in the scene.

@acs
Copy link
Contributor Author

acs commented May 23, 2020

For the future:

  • Create a specific SceneInteractive that can detect interactions with all the elements in a Scene. Or better, the current Scene could have a param to describe if it is interactive. In this case, an event loop is started.
  • When an interaction is detected a callback method is called: we can have a list of subscribers to be called upon events receiving. In the event we can include the Thing hit.

@acs
Copy link
Contributor Author

acs commented May 23, 2020

Development completed!

Next step is to merge the branch and to create the video for showing it in action.

If you right click with the sword the blocks, this block will be used to build the Thing. If you right click in the glass the default block for the Thing will be used.

If you unbuilt a Thing, the next time the default block will be used if you right click the glass.

Screenshot from 2020-05-23 19-41-56

@acs
Copy link
Contributor Author

acs commented May 23, 2020

I will add a new glass block at the center to hit it also. And move the tower further to see better the Scene. Little effort and much better result!

@acs
Copy link
Contributor Author

acs commented May 23, 2020

@acs
Copy link
Contributor Author

acs commented May 23, 2020

@acs acs closed this as completed May 23, 2020
McThings v0.30.0 automation moved this from In progress to Done May 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Work in the framework
Projects
No open projects
Development

No branches or pull requests

1 participant