User avatar
rpiMike
Posts: 1042
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: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

dsyleixa123
Posts: 571
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 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
:?:

User avatar
rpiMike
Posts: 1042
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 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')

dsyleixa123
Posts: 571
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 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?

User avatar
rpiMike
Posts: 1042
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 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.

dsyleixa123
Posts: 571
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 3:47 pm

aah, ok, I understand and try out!

dsyleixa123
Posts: 571
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 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)

Code: Select all

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

# ver 003

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 = 10   # size of game map                           #  
Map = [[0]*(msize+2) for _ in range(msize+2)] # plus 2 for border frame
Tmp = [[0]*(msize+2) for _ in range(msize+2)]



  
def putMap_Glider(x,z):  
     Map[x][z] = bl_0
     Map[x+1][z] = bl_0
     Map[x+2][z] = bl_1
                
     Map[x][z+1] = bl_1
     Map[x+1][z+1] = bl_0
     Map[x+2][z+1] = bl_1
                
     Map[x][z+2] = bl_0
     Map[x+1][z+2] = bl_1
     Map[x+2][z+2] = bl_1

     

def putField_Glider(x,y,z):  
    mc.setBlock(x, y, z, bl_0)
    mc.setBlock(x+1, y, z, bl_0)
    mc.setBlock(x+2, y, z, bl_1)
                
    mc.setBlock(x, 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, 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):
    for j in range(0,n):
      mc.setBlock(x+i, y, z+j, bl_0)
      
    
def clearField_radius(x,y,z, size):
  for i in range(-size,size):
    for j in range(-size,size):
      mc.setBlock(x+i, y, z+j, bl_0)


def copyField_Map():
  y=0   
  for x in range(0,msize):
    for z in range(0,msize):
      Map[x][z]=mc.getBlock(x,y,z)
      #debug
      print(x, z, Map[x][z])
      
      
      
#######################################
      

def countNeighbours(x,z):
  count = 0
  for i in range(-1,2):
       for j in range (-1,2):
            if((Map[x+i][z+j] == bl_1) and (i!=0 or j!=0)):
                 count=count+1
  return count

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


def calcGeneration():
    
  aliveNeighbours = 0
  
  for x in range(1,msize):
    for z in range(1,msize):
        
      aliveNeighbours=countNeighbours(x,z)
      print(x,z, aliveNeighbours)

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

      if aliveNeighbours>=2 and aliveNeighbours<=3:  # cell lives
        Tmp[x][z] = bl_1 

      if aliveNeighbours==3 :  # dead cell resurrects
        if Map[x][z] == bl_0:
          Tmp[x][z] = bl_1 
          
      if aliveNeighbours > 3:  # cell dies
        Tmp[x][z] = bl_0
          
          
  y=0
  for x in range(1,msize):                     # not tested yet
    for z in range(1,msize):
      Map[x][z] = Tmp[x][z]
      mc.setBlock(x, y, z, Tmp[x][z])  # not tested yet
  
  
#######################################






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

  putField_Glider(1,0,1)

  ######################
  #test, debug
  x=1
  y=0
  z=2
  print("Field:",x,z, mc.getBlock(x,y,z))
  Map[x][z]= mc.getBlock(x,y,z)
  print("Map  :",x,z, Map[x][z])
  alive=countNeighbours(x,z)
  print("Map   ", x,z, "alvNbs=",alive)
  print()

  
  x=2
  y=0
  z=2
  print("Field:",x,z, mc.getBlock(x,y,z))
  Map[x][z]= mc.getBlock(x,y,z)
  print("Map  :",x,z, Map[x][z])
  alive=countNeighbours(x,z)
  print("Map   ", x,z, "alvNbs=",alive)
  print()


  x=3
  y=0
  z=2
  print("Field:",x,z, mc.getBlock(x,y,z))
  Map[x][z]= mc.getBlock(x,y,z)
  print("Map  :",x,z, Map[x][z])
  alive=countNeighbours(x,z)
  print("Map   ", x,z, "alvNbs=",alive)
  print()
 



  ######################
  # import mc game Field to virtual MAP
  copyField_Map()

  
  ######################
  # test, debug
  x=1
  y=0
  z=2
  alive=countNeighbours(x,z)
  print("Map   ", x,z, "alvNbs=",alive)
  print()

  
  x=2
  y=0
  z=2
  alive=countNeighbours(x,z)
  print("Map   ", x,z, "alvNbs=",alive)
  print()


  x=3
  y=0
  z=2
  alive=countNeighbours(x,z)
  print("Map   ", x,z, "alvNbs=",alive)
  print()
 



  
  
  
  
  c=1  
  for c in (1,5):
     calcGeneration();

    
    
except KeyboardInterrupt:
  GPIO.cleanup() 
  
Last edited by dsyleixa123 on Thu Jan 16, 2020 7:42 pm, edited 4 times in total.

User avatar
rpiMike
Posts: 1042
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 4:53 pm

What are you actually trying to do? Why can't you just have an offset x & z to relocate the centre?

dsyleixa123
Posts: 571
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 5:48 pm

update
the simplified indices now appearantly are correct, just the code is still somehow (unexpectedly) bugged

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

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

Fri Jan 17, 2020 9:21 pm

PS, as to
What are you actually trying to do?
it's for my minecraft-implementation of Conway's Game of Life (you might have already guessed that meanwhile, probably 8)

Return to “Gaming”