Page 2 of 2

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

Posted: Thu Jan 16, 2020 1:59 pm
dsyleixa123 wrote:
Thu Jan 16, 2020 1:57 pm
the lowest level (z=-64)
why z?
isn't it y?
Sorry, yes, you are right its y=-64

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

Posted: Thu Jan 16, 2020 2:02 pm
so for the entire world:

Code: Select all

``````world.setBlocks(x1,y1,z1,  x2,y2,z2,  block_type)
world.setBlocks(-254,-20,-254,  254,0,254,  block.SANDSTONE.id)   # layer thickness of 20 blocks``````

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

Posted: Thu Jan 16, 2020 3:26 pm
It looks like worlds are not centred !

This works out the edges, then fills the world.

Code: Select all

``````import mcpi.minecraft as minecraft
import mcpi.block as block
import time

def findEdge(xz,inc):
v=0
id=0
while True:
if xz == 'x':
id = mc.getBlock(v,0,0)
else:
id = mc.getBlock(0,0,v)
#print(x,id)
if id==95 or (inc == -1 and v<-256) or (inc == 1 and v>256):
break
v+=inc

if inc == 1:
v-=1
else:
v+=1

return v

print('begin')

mc = minecraft.Minecraft.create()

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

minx = findEdge('x',-1)
minz = findEdge('z',-1)
maxx = findEdge('x',1)
maxz = findEdge('z',1)

print('min x',minx)
print('min z',minz)
print('max x',maxx)
print('max z',maxz)

print(maxx-minx+1,maxz-minz+1)

# fill sky
mc.setBlocks(minx,0,minz,maxx,64,maxz,0)

# fill ground
mc.setBlocks(minx,-20,minz,maxx,0,maxz,block.SANDSTONE.id)

mc.postToChat('finished')

print('end')
``````

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

Posted: Thu Jan 16, 2020 3:33 pm
I actually do not want to find edges, I just wanted an entire sandstone (id=24) plain like e.g.,

Code: Select all

``````mc.setBlocks(-128,-20,-128,  128,0,128,  24)
or even
mc.setBlocks(-254,-20,-254,  254,0,254,  24) ``````
for all and everything?

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

Posted: Thu Jan 16, 2020 3:37 pm
You need to know where the edges are or you may not fill your world. My code will fill the entire world.

If 254 works for you great, my Pi3 hung using 256.

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

Posted: Thu Jan 16, 2020 3:47 pm
aah, ok, I understand and try out!

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

Posted: Thu Jan 16, 2020 4:02 pm
indeed, it's extremely unsymmetrical:

begin
min x -13
min z -178
max x 242
max z 77
256 256
end

I'm afraid, for my purposes I needed a symmetrical map round (0,0) or a (0,0) origin map,
so either x=-100...+100, z=-100...+100
or perhaps x=0...200, z=0...200

but what mc provides is too odd, and probably mc is also far too slow for my purposes, too, as far I had tested...

but thank you very very much for your efforts so far, you really helped me a lot to learn and to understand about mc and Python! 8)

(edited, code see below)

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

Posted: Thu Jan 16, 2020 4:53 pm
What are you actually trying to do? Why can't you just have an offset x & z to relocate the centre?

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

Posted: Thu Jan 16, 2020 5:48 pm
update
the simplified indices now appearantly are correct, just the code is still somehow (unexpectedly) bugged

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

Posted: Mon Jan 20, 2020 12:50 pm
update:
it's for my mc Python implementation of Conway's Game Of Life -
and now it works! (silly bugs before!)
Nonetheless, it's incredible slow on my Pi 2, even on a 20x20 field .... and 200x200 (wishfully even up to 1000x1000) once had been intended!

Code: Select all

``````#!/usr/bin/python
import mcpi.minecraft as minecraft
import mcpi.block as block
import RPi.GPIO as GPIO
import time

# ver 004

mc = minecraft.Minecraft.create()

GPIO.setmode(GPIO.BCM)
p1 = 8
GPIO.setup(p1, GPIO.IN, GPIO.PUD_DOWN)

bl_1 = block.GRASS.id
bl_0 = block.SANDSTONE.id

msize = 20   # size of game map
Tmp = [[0]*(msize+2) for _ in range(msize+2)] # plus 2 for border frame

def putField_Glider(x,y,z):
mc.setBlock(x+0, y, z+0, bl_0)
mc.setBlock(x+1, y, z+0, bl_0)
mc.setBlock(x+2, y, z+0, bl_1)

mc.setBlock(x+0, y, z+1, bl_1)
mc.setBlock(x+1, y, z+1, bl_0)
mc.setBlock(x+2, y, z+1, bl_1)

mc.setBlock(x+0, y, z+2, bl_0)
mc.setBlock(x+1, y, z+2, bl_1)
mc.setBlock(x+2, y, z+2, bl_1)

#####################################

def clearField_n(x,y,z, n):
for i in range(0,n+1):
for j in range(0,n+1):
mc.setBlock(x+i, y, z+j, bl_0)

for i in range(-r,r+1):
for j in range(-r,r+1):
mc.setBlock(x+i, y, z+j, bl_0)

#######################################

def countNeighbours(x,y,z):
count = 0
for i in range(-1,2):
for j in range (-1,2):
if(( mc.getBlock(x+i,y,z+j) != bl_0) and (i!=0 or j!=0)):
count=count+1
return count

#######################################

def calcGeneration():

aliveNeighbours = 0
y = 0

for x in range(1,msize):
#debug
print("   line ", x, "/",msize-1)
for z in range(1,msize):

aliveNeighbours=countNeighbours(x,y,z)
#debug
#print(x,z, " alvNbs=",aliveNeighbours)

if aliveNeighbours < 2:  # cell dies
Tmp[x][z] = bl_0

if aliveNeighbours>=2 and aliveNeighbours<=3:  # cell lives
Tmp[x][z] = mc.getBlock(x,y,z)

if aliveNeighbours==3 :  # dead cell resurrects
if mc.getBlock(x,y,z) == bl_0:
Tmp[x][z] = bl_1

if aliveNeighbours > 3:  # cell dies
Tmp[x][z] = bl_0

y=0
for x in range(0,msize+1):                     # not tested yet
for z in range(0,msize+1):
if x==0 or z==0 or x==msize or z==msize:
Tmp[x][z] = bl_0
mc.setBlock(x,y,z, Tmp[x][z])

#######################################

try:
clearField_n(1,0,1, msize)
mc.setBlock(1,1,1, block.TORCH.id)

putField_Glider(1,0,1)

######################
# test,

for g in range (1,20):
print()
print("Generation= ", g)
calcGeneration();

except KeyboardInterrupt:
GPIO.cleanup()

``````

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

Posted: Mon Jan 20, 2020 3:25 pm
Couldn't help myself hack this about, basically do all of your calculations on 2 arrays, then just write each calculation output to Minecraft :

Code: Select all

``````import mcpi.minecraft as minecraft
import mcpi.block as block
import RPi.GPIO as GPIO
import time

# ver 004

def printTmp():
print('Tmp')
for row in Tmp:
for val in row:
if val == 24:
print('-',end='')
elif val == 2:
print('*',end='')
#print(f'{val:02} ',end='')
print('')

def printTmp2():
print('Tmp2')
for row in Tmp2:
for val in row:
if val == 24:
print('-',end='')
elif val == 2:
print('*',end='')
#print(f'{val:02} ',end='')
print('')

def putField_Glider(x,y,z):
#global Tmp
Tmp[x+0][z+0] = bl_0
Tmp[x+1][z+0] = bl_0
Tmp[x+2][z+0] = bl_1

Tmp[x+0][z+1] = bl_1
Tmp[x+1][z+1] = bl_0
Tmp[x+2][z+1] = bl_1

Tmp[x+0][z+2] = bl_0
Tmp[x+1][z+2] = bl_1
Tmp[x+2][z+2] = bl_1

#     mc.setBlock(x+0, y, z+0, bl_0)
#     mc.setBlock(x+1, y, z+0, bl_0)
#     mc.setBlock(x+2, y, z+0, bl_1)
#
#     mc.setBlock(x+0, y, z+1, bl_1)
#     mc.setBlock(x+1, y, z+1, bl_0)
#     mc.setBlock(x+2, y, z+1, bl_1)
#
#     mc.setBlock(x+0, y, z+2, bl_0)
#     mc.setBlock(x+1, y, z+2, bl_1)
#     mc.setBlock(x+2, y, z+2, bl_1)

#####################################

def clearField_n(x,y,z, n):
print('clearField_n()')
#for i in range(0,n+1):
#  for j in range(0,n+1):
#    mc.setBlock(x+i, y, z+j, bl_0)

for i in range(0,n):
for j in range(0,n):
Tmp2[x+i][z+j] = bl_0

for i in range(-r,r+1):
for j in range(-r,r+1):
mc.setBlock(x+i, y, z+j, bl_0)

#######################################

def countNeighbours(x,y,z):
count = 0
for i in range(-1,2):
for j in range (-1,2):
#print('i,j',i,j)
#if(((i!=0 or j!=0) and mc.getBlock(x+i,y,z+j) != bl_0)):
#     count+=1
if(( Tmp[x+i][z+j] != bl_0) and (i!=0 or j!=0)):
count=count+1

return count

#######################################

def calcGeneration():

aliveNeighbours = 0
y = 0

for x in range(1,msize):
#debug
print("   line ", x, "/",msize-1)
for z in range(1,msize):

aliveNeighbours=countNeighbours(x,y,z)
#debug
#print(x,z, " alvNbs=",aliveNeighbours)

if aliveNeighbours < 2:  # cell dies
Tmp2[x][z] = bl_0

if aliveNeighbours>=2 and aliveNeighbours<=3:  # cell lives
#Tmp2[x][z] = mc.getBlock(x,y,z)
Tmp2[x][z] = Tmp[x][z]

if aliveNeighbours==3 :  # dead cell resurrects
#if mc.getBlock(x,y,z) == bl_0:
if Tmp[x][z] == bl_0:
Tmp2[x][z] = bl_1

if aliveNeighbours > 3:  # cell dies
Tmp2[x][z] = bl_0

y=0
for x in range(0,msize+1):                     # not tested yet
for z in range(0,msize+1):
if x==0 or z==0 or x==msize or z==msize:
Tmp2[x][z] = bl_0
mc.setBlock(x,y,z, Tmp2[x][z])
Tmp[x][z] = Tmp2[x][z]

#######################################

try:
mc = minecraft.Minecraft.create()

GPIO.setmode(GPIO.BCM)
p1 = 8
GPIO.setup(p1, GPIO.IN, GPIO.PUD_DOWN)

bl_1 = block.GRASS.id
bl_0 = block.SANDSTONE.id

msize = 20   # size of game map
Tmp = [[bl_0]*(msize+2) for _ in range(msize+2)] # plus 2 for border frame
Tmp2 = [[bl_0]*(msize+2) for _ in range(msize+2)] # plus 2 for border frame

clearField_n(1,0,1, msize)
mc.setBlock(1,1,1, block.TORCH.id)

putField_Glider(1,0,1)

#printTmp()

######################
# test,

for g in range (1,20):
print()
print("Generation= ", g)
calcGeneration()
#printTmp2()
Tmp2 = [[bl_0]*(msize+2) for _ in range(msize+2)] # plus 2 for border frame

except KeyboardInterrupt:
GPIO.cleanup()

``````

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

Posted: Mon Jan 20, 2020 4:58 pm
yes, that was my approach before :
actually I already tried that, but it was not noteably faster, regrettably.
OTOH it then was lacking of a user-interface (putting optionally new blocks manually to the fields using the mc player)

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

Posted: Mon Jan 20, 2020 5:03 pm
perhaps multithreading could speed it up, calculating the neighbours from either field corner to the center point, and then writing all tmp values to the fields, also multi-threaded. But I actually doubt that Python and mc would support that, tbh...

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

Posted: Mon Jan 20, 2020 5:06 pm
dsyleixa123 wrote:
Mon Jan 20, 2020 4:58 pm
yes, that was my approach before :
actually I already tried that, but it was not noteably faster, regrettably.
OTOH it then was lacking of a user-interface (putting optionally new blocks manually to the fields using the mc player)
It seemed faster on my Pi4 with this approach.

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

Posted: Mon Jan 20, 2020 5:10 pm
yes, ok, well, perhaps a little, but one needed to copy all field blocks to tmp1 in each generation cycle, to read intermediate user actions, and at the very latest it's even slower than computing the "real" mc field with 1 single tmp map then, unfortunately.
Anyway, it was a nice challenge

.