dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Mon Jan 13, 2020 7:14 pm

Minecraft Pi edition (Stretch):
how to create a new world, just of an infinite plain of sand?

User avatar
rpiMike
Posts: 1532
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Mon Jan 13, 2020 7:49 pm

Google found the following:

https://www.minecraftforum.net/forums/m ... map-script

Code: Select all

import sys
import mcpi.minecraft as minecraft
import mcpi.block as block

mc = minecraft.Minecraft.create()
mc.setBlocks(-128,0,-128,128,64,128,0)
if(len(sys.argv) > 1):
    bid = int(sys.argv[1])
else:
    bid = block.SANDSTONE.id

if bid < 0 or bid > 108:
    bid = block.SANDSTONE.id

mc.setBlocks(-128,0,-128,128,-64,128,bid)

Take care as it will flatten the currently open map. You can also pass an argument: python3 flatmap.py <id>

User avatar
PeterO
Posts: 5968
Joined: Sun Jul 22, 2012 4:14 pm

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Mon Jan 13, 2020 7:58 pm

I'm pretty sure that relies on having installed the libraries for the "Adventures in Minecraft" book which the OP may not have done.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Mon Jan 13, 2020 9:12 pm

PeterO wrote:
Mon Jan 13, 2020 7:58 pm
I'm pretty sure that relies on having installed the libraries for the "Adventures in Minecraft" book which the OP may not have done.
PeterO
correct, I have just the basic "game" coming with Stretch, and a proprietary tutorial scenery (a folder called "adventskalender" in a minecraft subfolder) containing the files chunks.dat, entities.dat, and level.dat, level.dat_old)

User avatar
PeterO
Posts: 5968
Joined: Sun Jul 22, 2012 4:14 pm

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Mon Jan 13, 2020 9:54 pm

If you can I suggest getting a copy of this :
https://www.amazon.co.uk/Adventures-Min ... b_title_bk

The libraries are in the downloads section at
https://www.wiley.com/en-gb/Adventures+ ... 1119439585

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
rpiMike
Posts: 1532
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Mon Jan 13, 2020 10:04 pm

I didn't need to install any libraries. Worked for me.

User avatar
PeterO
Posts: 5968
Joined: Sun Jul 22, 2012 4:14 pm

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Mon Jan 13, 2020 10:19 pm

I haven't got a "clean" install to check.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Tue Jan 14, 2020 8:37 am

IIUC, the program above patches an existing "world".
What I mean is to create a plain sand desert world from the scratch, to get a new subfolder with new game files from wich I can start at the minecraft start window arbitrarily / optionally.
(tbh, I do not understand how minecraft worlds are generated and stored by which actual files)

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Tue Jan 14, 2020 9:34 am

PS,
as it just turned out, I cannot create a 2nd subfolder of an existing game world and then load either one optionally at the minecraft start window (for testing, I simply created a copy of the existing game subfolder):

Just 1 can be chosen, not the 2nd one which is listed but greyed out, I can just instead create a new random world (what I do not want).
How to fix that?
Last edited by dsyleixa123 on Wed Jan 15, 2020 12:12 pm, edited 3 times in total.

User avatar
PeterO
Posts: 5968
Joined: Sun Jul 22, 2012 4:14 pm

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Tue Jan 14, 2020 9:36 am

Sorry I can't help further. You're using things that I've not looked into.
PeterO,
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Tue Jan 14, 2020 1:34 pm

as it seems, the minecraft Pi edition is absolutely, totally crappy... :-/

User avatar
rpiMike
Posts: 1532
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Tue Jan 14, 2020 7:59 pm

You select other worlds by clicking and dragging left or right to select the required world.

User avatar
rpiMike
Posts: 1532
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Tue Jan 14, 2020 8:17 pm

The following code copies a Minecraft world folder to a new world folder and renames the world in the level.dat file.

I suggest backing up your original world just in case.

To run use :

python3 copyWorld.py <original world name> <new world name>

eg

Code: Select all

python3 copyWorld.py world MikesWorld1

Code: Select all

import os,sys,shutil

if(len(sys.argv) > 2):
    oldWorldName = sys.argv[1]
    newWorldName = sys.argv[2]
else:
    print('2 arguments required, <old world name> <new world name>')
    quit()

path = '/home/pi/.minecraft/games/com.mojang/minecraftWorlds/'

if len(newWorldName)<5:
    print('New world name must be at least 5 characters')
    quit()
    
if not os.path.exists(path+oldWorldName):
    print('Old world does not exist')
    quit()
    
if os.path.exists(path+newWorldName):
    print('New world already exists')
    quit()

# copy folder
shutil.copytree(path+oldWorldName,path+newWorldName)

os.rename(path+newWorldName+'/level.dat',path+newWorldName+'/level.dat_old2')

f = open(path+newWorldName+'/level.dat_old2','rb')
bOrig = bytearray(f.read())
bNew = bytearray()

str=''
i=0
levelNamePos=0
ignoreNext2= False
for ch in bOrig:
    str+=chr(ch)
    if levelNamePos>0 and i>levelNamePos:
        ignoreNext2 = False
        if ch==3:
            levelNamePos = 0
            newLevelName = newWorldName.encode()
            bNew.append(len(newLevelName))
            bNew.append(0)
            bNew += newLevelName
            bNew.append(ch)
    else:
        if not ignoreNext2:
          bNew.append(ch)
    
    if str.endswith('LevelName'):
        levelNamePos=i+2
        ignoreNext2 = True
    
    i+=1

fNew = open(path + newWorldName+'/level.dat','wb')
fNew.write(bNew)
fNew.close()


User avatar
PeterO
Posts: 5968
Joined: Sun Jul 22, 2012 4:14 pm

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Tue Jan 14, 2020 8:23 pm

rpiMike wrote:
Tue Jan 14, 2020 8:17 pm
The following code copies a Minecraft world folder to a new world folder and renames the world in the level.dat file.

I suggest backing up your original world just in case.

To run use :

python3 copyWorld.py <original world name> <new world name>

eg

Code: Select all

python3 copyWorld.py world MikesWorld1

Code: Select all

import os,sys,shutil

if(len(sys.argv) > 2):
    oldWorldName = sys.argv[1]
    newWorldName = sys.argv[2]
else:
    print('2 arguments required, <old world name> <new world name>')
    quit()

path = '/home/pi/.minecraft/games/com.mojang/minecraftWorlds/'

if len(newWorldName)<5:
    print('New world name must be at least 5 characters')
    quit()
    
if not os.path.exists(path+oldWorldName):
    print('Old world does not exist')
    quit()
    
if os.path.exists(path+newWorldName):
    print('New world already exists')
    quit()

# copy folder
shutil.copytree(path+oldWorldName,path+newWorldName)

os.rename(path+newWorldName+'/level.dat',path+newWorldName+'/level.dat_old2')

f = open(path+newWorldName+'/level.dat_old2','rb')
bOrig = bytearray(f.read())
bNew = bytearray()

str=''
i=0
levelNamePos=0
ignoreNext2= False
for ch in bOrig:
    str+=chr(ch)
    if levelNamePos>0 and i>levelNamePos:
        ignoreNext2 = False
        if ch==3:
            levelNamePos = 0
            newLevelName = newWorldName.encode()
            bNew.append(len(newLevelName))
            bNew.append(0)
            bNew += newLevelName
            bNew.append(ch)
    else:
        if not ignoreNext2:
          bNew.append(ch)
    
    if str.endswith('LevelName'):
        levelNamePos=i+2
        ignoreNext2 = True
    
    i+=1

fNew = open(path + newWorldName+'/level.dat','wb')
fNew.write(bNew)
fNew.close()

I think you are wasting your breath Mike. Toys seem to have been "thrown from the pram"
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Wed Jan 15, 2020 12:17 pm

rpiMike wrote:
Tue Jan 14, 2020 8:17 pm
The following code copies a Minecraft world folder to a new world folder and renames the world in the level.dat file.

I suggest backing up your original world just in case.

To run use :

python3 copyWorld.py <original world name> <new world name>

eg

Code: Select all

python3 copyWorld.py world MikesWorld1
thanks a lot, I'll soon try that!

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Wed Jan 15, 2020 1:37 pm

ok, update:
started your copy tool =>
it worked! I now have a 2nd world called new01
I could load it, do some things, leave it, reload it, all is fine.

edit, update:
now also the sand desert is fine!
again, thank you very much indeed! 8-) :geek:

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Thu Jan 16, 2020 12:09 pm

@rpiMike
unfortunately your script does not create SAND blocks at (x,0,z) for all x,z in range (-255,+255)
e.g., the sand desert is limited to x>-14, the rest beyond has the ID 95 (BEDROCK_INVISIBLE)
why is that so?
how can that be fixed?

PS:
just found out:
after some time all the blocks, one after the other, seem to vanish to the abyss, starting from the edges.... :o :shock:

User avatar
rpiMike
Posts: 1532
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Thu Jan 16, 2020 1:07 pm

I wonder if you closed Minecraft before the setBlocks methods had completed?

I've added some postToChat messages so that you can see then its finished.

Code: Select all

import sys
import mcpi.minecraft as minecraft
import mcpi.block as block
import time

print('begin')

mc = minecraft.Minecraft.create()

mc.postToChat('starting')
time.sleep(0.5)

mc.setBlocks(-128,0,-128,128,64,128,0)
if(len(sys.argv) > 1):
    bid = int(sys.argv[1])
else:
    bid = block.SANDSTONE.id

if bid < 0 or bid > 108:
    bid = block.SANDSTONE.id

mc.setBlocks(-128,0,-128,128,-64,128,bid)

mc.postToChat('finished')

print('end')

User avatar
rpiMike
Posts: 1532
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Thu Jan 16, 2020 1:08 pm

dsyleixa123 wrote:
Thu Jan 16, 2020 12:09 pm
@rpiMike
unfortunately your script does not create SAND blocks at (x,0,z) for all x,z in range (-255,+255)
e.g., the sand desert is limited to x>-14, the rest beyond has the ID 95 (BEDROCK_INVISIBLE)
why is that so?
how can that be fixed?

PS:
just found out:
after some time all the blocks, one after the other, seem to vanish to the abyss, starting from the edges.... :o :shock:
Oh - sand will fall if nothing is below it !

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Thu Jan 16, 2020 1:29 pm

so one will need to set a layer beneath? at which layer level and by which matter?

User avatar
rpiMike
Posts: 1532
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Thu Jan 16, 2020 1:35 pm

Lowest layer of your sand should be a block that doesn't move eg cobblestone (id 1).

Is there a reason that you wanted sand?

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Thu Jan 16, 2020 1:41 pm

actually because of the light color

tbh, I don't understand the setblocks thing:
set the 2 lowest y levels to id=1....?

x from -128 to +128 ?
y from -128 to -126 ???
z from -128 to +128 ?

User avatar
rpiMike
Posts: 1532
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Thu Jan 16, 2020 1:51 pm

If you just want the sand colour why not use sandstone - which won't fall.

If you were using sand, the lowest level (z=-64 y=-64) should be a block that won't fall.

setBlocks(-256,-64,-256,256,-64,256,1) # this would set lowest level z=-64 y=-64 to cobblestone

https://arghbox.wordpress.com/2013/07/0 ... ng-blocks/

Edit: My Pi3 locks up it I try a full 256 area
Last edited by rpiMike on Thu Jan 16, 2020 2:02 pm, edited 2 times in total.

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Thu Jan 16, 2020 1:54 pm

ah, ok, then I'll take sandstone perhaps, I didn't suppose them to behave so differently...

at which position in the inventory is sandstone, for "repairing" purposes?

dsyleixa123
Posts: 1025
Joined: Mon Jun 11, 2018 11:22 am

Re: Minecraft Pi edition (Stretch): how to create an infinite plain of sand?

Thu Jan 16, 2020 1:57 pm

the lowest level (z=-64)
why z?
isn't it y?

Code: Select all

 world.setBlocks(x1,y1,z1,  x2,y2,z2,  block_type)
Last edited by dsyleixa123 on Thu Jan 16, 2020 1:59 pm, edited 2 times in total.

Return to “Gaming”