How to enjoy programming with Minecraft (Ruby, Python)

If you install Raspberry Jam Mod in Minecraft PC version, you can play by moving blocks and players in Minecraft programmatically.

57e43a54.png

Outline of procedure

  1. Install Minecraft
  2. Install Forge
  3. Install the mod
  4. Install gem (for Ruby)
  5. Program execution

environment

--OS X 10.11 El Capitan or Windows 7

1-a. Install Minecraft

Purchase from Minecraft's Website (US $ 26.95) or install the trial version. (For the trial version, click "Download it here" under "Get Minecraft" on the right side of the site)

1-b. Launch Minecraft

When you launch Minecraft, Minecraft Launcher (1.6.48) will be launched.

1-c. Profile settings

Set to release 1.8.x.

  1. Profile with the user name should be displayed in "Profile" at the bottom left of Minecraft Launcher, so press the "Edit Profile" button.
  2. Select the latest "release 1.8.8" in "Use Version".
  3. Click the "Save Profile" button at the bottom right to save the settings.

1-d. Create a new world with Minecraft

To install Forge next time, you need to start the world made with 1.8 series once.

  1. Press "Play" on Minecraft Launcher to launch Minecraft (1.8.8).
  2. Press "Singleplayer" and then "Create New World" to create a Minecraft world. (World name and game mode are your choice.)
  3. Play a little and see how it works, then quit Minecraft.

* Basic operation of Minecraft

○ Keyboard

--W forward --S retreat --A Horizontal movement to the left --D Horizontal movement to the right --E item list (close with Esc) --Twice space quickly Switch between flight mode / normal mode (Flight mode is creative mode only)

--Space rise (flying mode) / jump (normal mode) --Left Shift descent (flying mode) / crouching (normal mode) --Esc menu screen (settings, publish to LAN, save and return to title), move mouse cursor off screen --T Chat / server command, move mouse cursor off screen

○ Mouse

--Mouse cursor Change the viewing direction --Right click place a block --Break the left click block --Select from items in the wheel hot bar (or specify with keys 1-9)

○ Function keys (For Mac and laptop, press with fn key)

--F1 Head-up display (additional information) Display switching --Taking F2 screenshots Storage location; ・ Mac; ~ / Library / Application Support / minecraft / versions / 1.8-Forge11.14.4.1563 / screenshots -Windows; C: \ Users \ username \ AppData \ Roaming \ .minecraft \ versions \ screenshots

--F3 Debug information display switching, other functions in combination with other keys

--F5 Viewpoint switching (self, from behind, from front) --F11 Full screen display switching (on Mac, even when fn + option + F11)

2-a. Install Minecraft Forge

Install Minecraft Forge to manage mods.

  1. In Minecraft Forge's Website, select "1.8" for "Minecraft Versions" and select "Installer" for "Download Recommended (11.14.4.1563)" (for Windows). Click "Installer-win").
  2. The advertisement will be displayed, but after a few seconds, press the "SKIP" button on the upper right to start the download. (If you want to select the version, click "Show all downloads".)
  3. Double-click the downloaded forge-1.8-11.14.4.1563-installer.jar to install it.

→ ・ [1.8 compatible] Mod introduced to Minecraft on Mac OS X --AQUAALTA → ・ [[Minecraft] You can install this! How to install a modified new mod-Explanation of Forge and folder settings [1.7.10 / 1.8 ~] --Napoan Micra](http://napoan.com/archives/ new-way-to-install-mod.html) → ・ [Minecraft] 1.8 compatible First mod installation method for Windows --AQUAALTA

2-b. Profile settings again (create settings for Forge)

  1. Start Minecraft again.

  2. "Forge" Profile should be added to "Profile" at the bottom left of Minecraft Launcher, so select it and press the "Edit Profile" button.

  3. Select the Forge version "release 1.8-Forge 11.14.4.1563" installed in "Use Version".

  4. Check "Game Directory" in "Profile Info" and check /Users/username/Library/Application Support/minecraft/versions/1.8-Forge11.14.4.1563 (Mac) or C: \ Users \ Username \ AppData \ Roaming \ .minecraft \ versions \ 1.8-Forge-11.14.4.1563 (Windows) Specify as.

Five. After setting, click the "Save Profile" button at the bottom right to save the setting.

2-c. Launch Minecraft (Confirm Forge installation)

  1. Make sure that "Profile" of Minecraft Launcher is "Forge" and press "Play". Minecraft with Forge applied starts.
  2. When Forge is applied, the number of "Mods" buttons will increase, and you will see the Forge version etc. displayed at the bottom left of the screen.

3-a. Install Raspberry Jam Mod

  1. Click "releases" at the top of GitHub site of Raspberry Jam Mod. click.

  2. Click "RaspberryJamMod.jar" in "Downloads" of "Latest release (0.51)" to download.

  3. Place the downloaded RaspberryJamMod.jar in "mods" in the directory specified in "Game Directory" earlier (on Mac, / Users / username / Library / Application Support / minecraft / versions / 1.8-Forge11.14.4.1563). Move or copy into the folder.

※ Caution; For Windows, select "RaspberryJamMod.jar" in "Downloads". If you select "RaspberryJamMod-Installer.exe", RaspberryJamMod.jar will be automatically installed in a different folder than the above.

3-b. Launch Minecraft (Confirm installation of Raspberry Jam Mod)

  1. Confirm that "Profile" of Minecraft Launcher is "Forge" again, and press "Play".
  2. When Minecraft starts, press the "Mods" button. If there is "Raspberry Jam Mod" in the list of mods on the left side, it is installed.

3-c. Create a new world (settings when switching windows)

  1. Select "Single Play" to check the operation, enter "Creative" for "Game Mode" and "World Name" as you like, and press "Create New World".
  2. On the created world screen, press F3 + P (or fn + F3 + P) to pause or prevent the game menu from appearing when another window becomes active. (After this, if the debug screen display is in the way, press F3.)
  3. Switch to another window with Cmd + Tab (Mac) or Alt + Tab (Windows). (Keep two or more windows open)
  4. Make sure that the game menu does not appear on the world screen and does not pause.

Four. Install Minecraft-Pi-Ruby gem (for Ruby)

4-A. Regular Minecraft-Pi-Ruby gem installation

$ gem install minecraft-pi-ruby
Successfully installed minecraft-pi-ruby-0.0.1
Parsing documentation for minecraft-pi-ruby-0.0.1
Done installing documentation for minecraft-pi-ruby after 1 seconds
1 gem installed

4-B. Install your own extended Minecraft-Pi-Ruby gem (recommended)

It lacked functionality compared to Python, so I added it. → ・ https://github.com/noanoa07/minecraft-pi-ruby/tree/feature

$ gem install specific_install
$ gem specific_install https://github.com/noanoa07/minecraft-pi-ruby.git feature

5-A. Program execution (Ruby)

5-A-1. Write a Ruby program

hello.rb


require 'minecraft-pi-ruby'

mc = Minecraft.new
mc.say 'Hello Minecraft World!'

5-A-2. Ruby program execution

Keep the Minecraft world open;

$ ruby hello.rb

On the screen of Minecraft World; hello minecraft world! Is displayed, it is successful!

5-B. Program execution (Python)

5-B-1. MCPI folder

  1. Download python2-scripts.zip (for Python2) or python3-scripts.zip (for Python3) from the Raspberry Jam Mod GitHub site And deploy.

  2. The expanded "mcpipy" folder contains various Python sample programs, as well as the "MCPI" folder.

5-B-2. Write a python program

Create it in the same location as the MCPI folder.

hello.py


import mcpi.minecraft as minecraft
 
mc = minecraft.Minecraft.create()
mc.postToChat("Hello Minecraft World!")

5-B-3. Executing a Python program

Keep the Minecraft world open;

$ cd  mcpipy
$ python hello.py

On the screen of Minecraft hello minecraft world! Is displayed, it is successful!

Try running other sample programs in the mcpipy folder.

Reference A. Minecraft-Pi-Ruby command list

○ Initial setting

require 'minecraft-pi-ruby'  mc = Minecraft.new

The above two lines are required for execution. (Mc is an arbitrary variable name.)

○ Command

--set_camera_mode (Raspberry Pi environment only) Set camera mode (: fixed,: normal,: follow)

--set_block (x, y, z, block ID [, block data]) or set_block (position, block ID [, block data])

Example) set_block (0, 0, 0, Block :: STONE) The block ID can be a number Block data can be omitted (Block ID and block data will be described later)

--get_block (x, y, z) * Original extension Returns the block ID of coordinates (x, y, z)

--set_blocks or make_cuboid Arguments can be specified as (x1, y1, z1, x2, y2, z2, block ID [, block data]) or (position1, position2, block ID [, block data]).

Example) set_blocks (0, 0, 0, 20, 20, 20, Block :: OBSIDIAN) The block ID can be a number Block data can be omitted (Block ID and block data will be described later)

--get_ground_height (x, z) or ground_height (x, z) Returns the ground height (y coordinate) at coordinates (x, z)

--set_player_position (x, y, z) or set_player_position (position) Place the player in coordinates (x, y, z)

--get_player_position * Original extension Returns the player coordinates in the Position class.

--Getting keystrokes It is not possible (currently) to get keystroke information from Minecraft. Also, when the Minecraft window is active, you can't get keystrokes for programs running in the terminal. Therefore, by displaying the Minecraft window while activating the terminal window, the key input information is acquired on the terminal side. (In 3-c. "Settings when switching windows" above, even if another window becomes active, pause it or prevent the game menu from appearing.)   You can use Ruby's io / console library to get keystrokes. → ・ Ruby --Get terminal key input and move the cursor (without curses) --Qiita

Reference B. Sample program (Ruby)

(license; public domain)

○ Display characters on the screen

hello.rb



require 'minecraft-pi-ruby'

mc = Minecraft.new
mc.say 'Hello Minecraft World!'

○ Flatten the land

reset.rb


require 'minecraft-pi-ruby'

mc = Minecraft.new

sleep 5
mc.say 'Reset this World!'
mc.set_blocks(-100,   0, -100, 100, 63, 100, Block::AIR)
mc.set_blocks(-100,  -1, -100, 100, -1, 100, Block::GRASS)
mc.set_blocks(-100, -63, -100, 100, -2, 100, Block::STONE)

mc.set_player_position(0, 100, 0)

○ Place the block on the ground in the shape of a letter

chars.rb


require 'minecraft-pi-ruby'

mc = Minecraft.new

chars = [
'#####   #    #  ####   #    #   #',
'#    #  #    #  #   #   #  #    #',
'#   #   #    #  ####     #      #',
'####    #    #  #   #    #      #',
'#   #   #    #  #   #    #       ',
'#    #   ####   ####     #      #',
]

sleep 5
mc.set_player_position(0, 100, 0)
mc.say 'Hello Ruby !'

# Reset the world
mc.set_blocks(-100,   0, -100, 100, 63, 100, Block::AIR)
mc.set_blocks(-100,  -1, -100, 100, -1, 100, Block::GRASS)
mc.set_blocks(-100, -63, -100, 100, -2, 100, Block::STONE)

x = -10
y =   0
z = -10


chars.each do |line|
  line.each_char do |ch|
    if ch == '#'
      mc.set_block(x, y, z, Block::GOLD_BLOCK)
    end
  x += 1
  end
  x = -10
  z += 1
end

Reference) → ・ Study programming while playing with Minecraft Pi Edition! --TONGARISM.COM

○ Display the pressed key

chat.rb


require 'minecraft-pi-ruby'
require 'io/console'

mc = Minecraft.new
mc.say 'chat start!'

# ctrl + C to exit
while ch = STDIN.getch
  exit if ch == ?\C-c
  mc.say ch
end

Reference C. Block ID, block data

○ Block ID (* indicates block data)

0 AIR (air, leave nothing) 1 STONE (stone) 2 GRASS 3 DIRT (Sat) 4 COBBLESTONE (cobblestone) 5 * WOOD_PLANKS 6 * SAPLING (sapling) 7 BEDROCK 8 WATER_FLOWING WATER (Wednesday) 9 * WATER_STATIONARY (stationary water) 10 LAVA_FLOWING LAVA (lava) 11 * LAVA_STATIONARY (stationary lava) 12 SAND 13 GRAVEL 14 GOLD_ORE (gold ore) 15 IRON_ORE (iron ore) 16 COAL_ORE (coal ore) 17 * WOOD 18 * LEAVES 20 GLASS 21 LAPIS_LAZULI_ORE (lapis lazuli ore) 22 LAPIS_LAZULI_BLOCK 24 * SANDSTONE 26 BED 30 COBWEB (cobweb) 31 * GRASS_TALL (grass) 35 * WOOL (wool) 37 FLOWER_YELLOW (yellow flower) 38 FLOWER_CYAN (red rose) 39 MUSHROOM_BROWN (mushroom tea) 40 MUSHROOM_RED (mushroom red) 41 GOLD_BLOCK 42 IRON_BLOCK (iron block) 43 * STONE_SLAB_DOUBLE (overlapping half blocks) 44 * STONE_SLAB (half block) 45 BRICK_BLOCK 46 * TNT (TNT bomb) 47 BOOKSHELF (bookshelf) 48 MOSS_STONE (moss stone) 49 OBSIDIAN (Obsidian) 50 * TORCH (Torches) 51 FIRE 53 * STAIRS_WOOD (Oak tree stairs) 54 * CHEST 56 DIAMOND_ORE (diamond ore) 57 DIAMOND_BLOCK 58 CRAFTING_TABLE (workbench) 60 FARMLAND (arable land) 61 * FURNACE_INACTIVE (Kamado) 62 * FURNACE_ACTIVE (Burning Kamado) 64 DOOR_WOOD (wooden door) 65 * LADDER 67 * STAIRS_COBBLESTONE (log stairs) 71 DOOR_IRON (iron door) 73 REDSTONE_ORE (red stone ore) 78 SNOW (snow) 79 ICE (ice) 80 * SNOW_BLOCK (snow block) 81 CACTUS 82 CLAY 83 SUGAR_CANE (cactus) 85 FENCE 89 GLOWSTONE_BLOCK 95 BEDROCK_INVISIBLE (locked chest) 98 * STONE_BRICK (stone brick) 102 GLASS_PANE (flat glass) 103 MELON (watermelon block) 107 * FENCE_GATE 246 GLOWING_OBSIDIAN (shining obsidian) 247 * NETHER_REACTOR_CORE (Nether Reactor Core)

○ Block data

5 WOOD_PLANKS  0: Oak  1: Spruce  2: Birch  3: Jungle

6 SAPLING (sapling)  0: Oak  1: Spruce  2: Birch  3: Jungle

9 WATER_STATIONARY (stationary water) 11 LAVA_STATIONARY (stationary lava)  0-7: Level of the water, 0 being the highest, 7 the lowest (0-7: height, 0 is the lowest, 7 is the highest)

17 WOOD   0: Oak (up/down)   1: Spruce (up/down)   2: Birch (up/down)   3: Jungle (up/down)   4: Oak (east/west)   5: Spruce (east/west)   6: Birch (east/west)   7: Jungle (east/west)   8: Oak (north/south)   9: Spruce (north/south)  10: Birch (north/south)  11: Jungle (north/south)  12: Oak (only bark)  13: Spruce (only bark)  14: Birch (only bark)  15: Jungle (only bark)

18 LEAVES  1: Oak leaves  2: Spruce leaves  3: Birch leaves

24 SANDSTONE  0: Sandstone  1: Chiseled sandstone  2: Smooth sandstone

31 GRASS_TALL (grass)  0: Shrub  1: Grass  2: Fern  3: Grass (color affected by biome)

35 WOOL (wool)   0: White   1: Orange   2: Magenta   3: Light Blue   4: Yellow   5: Lime   6: Pink   7: Grey   8: Light grey   9: Cyan  10: Purple  11: Blue  12: Brown  13: Green  14: Red  15:Black

43 STONE_SLAB_DOUBLE (stacked half blocks) 44 STONE_SLAB (half block)  0: Stone  1: Sandstone  2: Wooden  3: Cobblestone  4: Brick  5: Stone Brick  6: Nether Brick  7: Quartz

46 TNT (TNT bomb)  0: Inactive  1: Ready to explode

50 TORCH (Torches)  1: Pointing east  2: Pointing west  3: Pointing south  4: Pointing north  5: Facing up

53 STAIRS_WOOD (Oak tree stairs) 67 STAIRS_COBBLESTONE (log stairs)  0: Ascending east  1: Ascending west  2: Ascending south  3: Ascending north  4: Ascending east (upside down)  5: Ascending west (upside down)  6: Ascending south (upside down)  7: Ascending north (upside down)

54 CHEST 61 FURNACE_INACTIVE (Kamado) 62 FURNACE_ACTIVE (Burning Kamado) 65 LADDER 107 FENCE_GATE  2: Facing north  3: Facing south  4: Facing west  5: Facing east

80 SNOW_BLOCK (snow block)  0-7: Height of snow, 0 being the lowest, 7 being the highest. (0-7: Snow height, 0 is the lowest, 7 is the highest)

98 STONE_BRICK (stone brick)  0: Stone brick  1: Mossy stone brick  2: Cracked stone brick  3: Chiseled stone brick

247 NETHER_REACTOR_CORE (Nether Reactor Core)  0: Unused  1: Active  2: Stopped / used up

→ ・ Minecraft API-\

reference;

(Continued by "Next" or "View All Steps" at the bottom of the screen)

Original article;

-Four ways to enjoy programming with Minecraft -How to enjoy programming by putting mods in Minecraft PC version -Minecraft Programming in Ruby -How to move the mouse pointer off the screen in Minecraft and not pause

Recommended Posts

How to enjoy programming with Minecraft (Ruby, Python)
How to enjoy Python on Android !! Programming on the go !!
Python: How to use async with
How to get started with Python
How to use FTP with Python
How to calculate date with python
How to work with BigQuery in Python
How to do portmanteau test with python
How to display python Japanese with lolipop
How to enter Japanese with Python curses
[Python] How to deal with module errors
How to write Ruby to_s in Python
How to install python3 with docker centos
How to upload with Heroku, Flask, Python, Git (4)
How to read a CSV file with Python 2/3
[REAPER] How to play with Reascript in Python
How to do multi-core parallel processing with python
How to install Python
Strategy on how to monetize with Python Java
3. 3. AI programming with Python
[Python] How to draw multiple graphs with Matplotlib
[Python] How to read excel file with pandas
How to crop an image with Python + OpenCV
How to install python
Python programming with Atom
How to specify attributes with Mock of python
Competitive programming with python
How to measure execution time with Python Part 1
How to use tkinter with python in pyenv
[Python] How to handle Japanese characters with openCV
Programming with Python Flask
[Python] How to compare datetime with timezone added
How to measure execution time with Python Part 2
Try to solve the programming challenge book with python3
How to add help to HDA (with Python script bonus)
[Python] How to draw a line graph with Matplotlib
How to scrape image data from flickr with python
How to do hash calculation with salt in Python
[Introduction to Python] How to iterate with the range function?
Explain in detail how to make sounds with python
How to upload with Heroku, Flask, Python, Git (Part 3)
How to run tests in bulk with Python unittest
[Python] How to specify the download location with youtube-dl
How to measure mp3 file playback time with python
How to use python interactive mode with git bash
How to convert JSON file to CSV file with Python Pandas
How to upload with Heroku, Flask, Python, Git (Part 1)
[Python] How to deal with pandas read_html read error
How to upload with Heroku, Flask, Python, Git (Part 2)
How to get mouse wheel verdict with Python curses
[Python] How to rewrite the table style with python-pptx [python-pptx]
python, php, ruby How to convert decimal numbers to n-ary numbers
[Python] How to create a 2D histogram with Matplotlib
How to switch to smartphone mode with Python + Selenium + Chrome
Something to enjoy with Prim Pro (X-Play) and Python
How to operate Discord API with Python (bot registration)
[Python] How to draw a scatter plot with Matplotlib
How to handle JSON in Ruby, Python, JavaScript, PHP
Programming with Python and Tkinter
Connect to BigQuery with Python
[2020.8 latest] How to install Python