Thursday, December 29, 2016

Used Python to Find Diamond Ore in Minecraft

I have been working on learning Python by creating mods in Minecraft.  Working my way through this Learn to Program With Minecraft book and I decided to modify one of the missions in chapter four that talks about posting a message to the users.  Well one message that I have always wanted to see is if there are diamonds around me.  I wrote a script with some loop nesting and slow as can be, but it finds diamond ore and posts a message with position values so I can find them.  Below is that script.

from mcpi.minecraft import Minecraft
from mcpi.minecraft import Block
mc = Minecraft.create()

pos = mc.player.getPos()
distance = 10
totalCheck = 0
for x in range(int(pos.x), int(pos.x + distance)):
    for y in range(4, 17):
        for z in range(int(pos.z), int(pos.z + distance)):
                blockId = mc.getBlock(x, y, z)
                totalCheck += 1
                if (blockId == 56):
                    mc.postToChat("block: " + str(blockId) + "x: " + str(x) + " y: " + str(y) + " z: " + str(z))

mc.postToChat("Total blocks checked: " + str(totalCheck))



5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. If you are looking for a professional developers to develop your professional software. You can opt for quality IOS application development online Australia for more information.

    ReplyDelete
  3. Great work man i would like to congratulate you on this effort 對戒


    ReplyDelete
  4. You have worked nicely with your insights that makes our work easy. The information you have provided is really factual and significant for us. Keep sharing these types of articles, Thank you.tumbled stones india

    ReplyDelete
  5. You have worked nicely with your insights that makes our work easy. The information you have provided is really factual and significant for us. Shop Lepidolite Heart Carving Online Keep sharing these types of article, Thank you.

    ReplyDelete