SonarDeLInfini/Python/minecrafter.py

70 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
"""
Created on Fri Jun 14 14:16:11 2019
@author: savrillon
"""
from data import WorldChunk
import math
import numpy as np
import mcpi.minecraft as minecraft
import random
import mcpi.block as block
from perlin import CavernedNoise2
mc = minecraft.Minecraft.create()
mc.postToChat("Hello World !")
playerPos = mc.player.getPos()
tp = True
lights = True
chunk = (math.floor(playerPos.x/16),math.floor(playerPos.z/16))
noise = CavernedNoise2(456)
size = 64
for i in range(0,size):
for j in range(0,size):
cx,cy = chunk[0]+i,chunk[1]+j
print("Géneration de "+str(i)+","+str(j))
mc.postToChat("Géneration de "+str(i)+","+str(j))
if tp:
mc.player.setPos(cx*16+8,playerPos.y,cy*16+8)
data = noise.getChunk(cx,cy,(16,16))
#print(data)
#data = np.abs(data)
x0,z0 = cx*16,cy*16
x1,z1 = x0 + 15 , z0 + 15
y0,y1 = 4,128-1
h = y1-y0
mc.setBlocks(x0,y0,z0,x1,y1,z1,block.IRON_BLOCK)
for dx in range(0,16):
for dz in range(0,16):
x,z = x0+dx,z0+dz
boule = True
fm1 = y0
for f in sorted(data[dx][dz]):
if f < 0 :print(f)
mc.setBlocks(x,y0+fm1,z,x,y0+f,z,block.STONE if boule else block.AIR)
#mc.setBlock(x,y0+fm1,z,x,d,z,block.STONE if boule else block.AIR)
boule = not boule
fm1 = f
mc.setBlocks(x,y0+fm1,z,x,y1,z,block.AIR)
if(lights):
for _ in range(256*size**2):
x=random.randint(0,size*16)+chunk[0]*16
y=random.randint(y0,y1)
x=random.randint(0,size*16)+chunk[1]*16
if(mc.getBlock(x,y,z)==block.STONE.id):
mc.setBlock(x,y,z,block.GLOWSTONE_BLOCK)
print(chunk)