File size: 2,777 Bytes
dead840
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""构造非对称、跨区块、有水层与方块实体的测试样例。"""
from pathlib import Path
import sys
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
import numpy as np
import amulet_nbt as n
from converter.formats import Scene,write_schem,write_mcstructure
from converter.nbtio import compounds,ints,floats

def sample_java():
    p=['minecraft:air','minecraft:stone','minecraft:oak_planks','minecraft:glass',
       'minecraft:oak_stairs[facing=east,half=bottom,shape=straight,waterlogged=true]',
       'minecraft:oak_log[axis=y]','minecraft:gold_block','minecraft:chest[facing=north,type=single,waterlogged=false]']
    b=np.zeros((19,9,23),np.int32); b[:,0,:]=1
    b[2:17,1,3:20]=2
    for x in (2,16): b[x,2:7,3:20]=3
    for z in (3,19): b[2:17,2:7,z]=3
    b[2:17,7,3:20]=2; b[4,2,4]=4; b[8,2:8,10]=5; b[17,8,21]=6; b[6,2,6]=7
    be={(6,2,6):n.CompoundTag({'id':n.StringTag('minecraft:chest'),'x':n.IntTag(6),'y':n.IntTag(2),'z':n.IntTag(6),'CustomName':n.StringTag('{"text":"测试箱子 中文 🧱"}'),'Items':compounds([n.CompoundTag({'id':n.StringTag('minecraft:diamond'),'count':n.IntTag(12),'Slot':n.ByteTag(0)})])})}
    return Scene('java',b.shape,p,b,block_entities=be,data_version=4189,origin=(-3,1,7))

def sample_bedrock():
    def block(name,states={}): return n.CompoundTag({'name':n.StringTag('minecraft:'+name),'states':n.CompoundTag(states),'version':n.IntTag(18168865)})
    p=[block('air'),block('stone'),block('oak_stairs',{'upside_down_bit':n.ByteTag(0),'weirdo_direction':n.IntTag(0)}),block('water',{'liquid_depth':n.IntTag(0)}),block('chest',{'minecraft:cardinal_direction':n.StringTag('north')}),block('gold_block')]
    b=np.zeros((19,9,23),np.int32); b[:,0,:]=1; b[2:17,1,3:20]=1; b[1,1,1]=2; b[6,2,6]=4; b[17,8,21]=5; b[4,3,9]=-1
    water=np.full(b.shape,-1,np.int32); water[1,1,1]=3
    be={(6,2,6):n.CompoundTag({'id':n.StringTag('Chest'),'x':n.IntTag(6),'y':n.IntTag(2),'z':n.IntTag(6),'CustomName':n.StringTag('保留箱子 中文 🧱'),'isMovable':n.ByteTag(1),'Items':compounds([n.CompoundTag({'Name':n.StringTag('minecraft:diamond'),'Count':n.ByteTag(12),'Damage':n.ShortTag(0),'Slot':n.ByteTag(0)})])})}
    entities=[n.CompoundTag({'identifier':n.StringTag('minecraft:pig'),'Pos':floats((7.5,2,8.5)),'Rotation':floats((0,0)),'UniqueID':n.LongTag(42),'Health':n.ShortTag(10),'Persistent':n.ByteTag(1),'Tags':n.ListTag([n.StringTag('测试')])})]
    return Scene('bedrock',b.shape,p,b,water,block_entities=be,entities=entities,origin=(113,65,-81))

if __name__=='__main__':
    out=Path(__file__).resolve().parents[1]/'samples'; out.mkdir(exist_ok=True)
    write_schem(sample_java(),out/'demo-java-v3.schem',3)
    write_mcstructure(sample_bedrock(),out/'demo-bedrock-v1.mcstructure',1)
    print(out)