Page 1 of 2

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

Posted: Mon Jan 13, 2020 7:14 pm
by dsyleixa123
Minecraft Pi edition (Stretch):
how to create a new world, just of an infinite plain of sand?

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

Posted: Mon Jan 13, 2020 7:49 pm
by rpiMike
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>

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

Posted: Mon Jan 13, 2020 7:58 pm
by PeterO
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

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

Posted: Mon Jan 13, 2020 9:12 pm
by dsyleixa123
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)

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

Posted: Mon Jan 13, 2020 9:54 pm
by PeterO
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

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

Posted: Mon Jan 13, 2020 10:04 pm
by rpiMike
I didn't need to install any libraries. Worked for me.

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

Posted: Mon Jan 13, 2020 10:19 pm
by PeterO
I haven't got a "clean" install to check.
PeterO

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

Posted: Tue Jan 14, 2020 8:37 am
by dsyleixa123
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)

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

Posted: Tue Jan 14, 2020 9:34 am
by dsyleixa123
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?

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

Posted: Tue Jan 14, 2020 9:36 am
by PeterO
Sorry I can't help further. You're using things that I've not looked into.
PeterO,

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

Posted: Tue Jan 14, 2020 1:34 pm
by dsyleixa123
as it seems, the minecraft Pi edition is absolutely, totally crappy... :-/

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

Posted: Tue Jan 14, 2020 7:59 pm
by rpiMike
You select other worlds by clicking and dragging left or right to select the required world.

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

Posted: Tue Jan 14, 2020 8:17 pm
by rpiMike
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()


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

Posted: Tue Jan 14, 2020 8:23 pm
by PeterO
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

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

Posted: Wed Jan 15, 2020 12:17 pm
by dsyleixa123
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!

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

Posted: Wed Jan 15, 2020 1:37 pm
by dsyleixa123
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:

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

Posted: Thu Jan 16, 2020 12:09 pm
by dsyleixa123
@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:

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

Posted: Thu Jan 16, 2020 1:07 pm
by rpiMike
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')

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

Posted: Thu Jan 16, 2020 1:08 pm
by rpiMike
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 !

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

Posted: Thu Jan 16, 2020 1:29 pm
by dsyleixa123
so one will need to set a layer beneath? at which layer level and by which matter?

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

Posted: Thu Jan 16, 2020 1:35 pm
by rpiMike
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?

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

Posted: Thu Jan 16, 2020 1:41 pm
by dsyleixa123
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 ?

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

Posted: Thu Jan 16, 2020 1:51 pm
by rpiMike
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

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

Posted: Thu Jan 16, 2020 1:54 pm
by dsyleixa123
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?

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

Posted: Thu Jan 16, 2020 1:57 pm
by dsyleixa123
the lowest level (z=-64)
why z?
isn't it y?

Code: Select all

 world.setBlocks(x1,y1,z1,  x2,y2,z2,  block_type)