2016-08-18 08:40:15 +00:00
import logging
2016-08-24 11:17:42 +00:00
import re
2014-03-04 13:04:53 +00:00
from itemstack import *
2015-03-09 09:36:34 +00:00
#If you wish to add more entities, then...
# To print out pre and post-conversion entity information uncomment line 237 (ish) in blocks.py (search for 'EntityInfo' to locate it)
2014-03-04 13:04:53 +00:00
2016-08-18 08:40:15 +00:00
logger = logging . getLogger ( ' tile_entities ' )
2014-02-08 18:47:28 +00:00
def convert_chest ( te ) :
2014-03-04 18:07:25 +00:00
formspec = " size[8,9] " + \
" list[current_name;main;0,0;8,4;] " + \
" list[current_player;main;0,5;8,4;] "
2014-03-04 13:04:53 +00:00
fields = { " infotext " : " Chest " ,
" formspec " : formspec }
inventory = { " main " : ( 0 , [ MTItemStack ( ) ] * 32 ) }
return None , None , ( fields , inventory )
2014-02-08 18:47:28 +00:00
def escape ( s ) :
s2 = " "
for c in s :
if c in [ " ' " , ' " ' , " \\ " ] :
s2 + = " \\ "
s2 + = c
elif c == " \n " :
s2 + = " \\ n "
elif c == " \t " :
s2 + = " \\ t "
else :
s2 + = c
return s2
2014-02-09 16:37:11 +00:00
def convert_furnace ( te ) :
src_time = 0
src_totaltime = 0
fuel_time = 0
fuel_totaltime = 0
infotext = " Furnace out of fuel "
2014-03-04 18:07:25 +00:00
formspec = " size[8,9] " + \
" image[2,2;1,1;default_furnace_fire_bg.png] " + \
" list[current_name;fuel;2,3;1,1;] " + \
" list[current_name;src;2,1;1,1;] " + \
" list[current_name;dst;5,1;2,2;] " + \
" list[current_player;main;0,5;8,4;] "
2014-03-04 13:04:53 +00:00
fields = { " infotext " : infotext ,
" formspec " : formspec ,
" src_totaltime " : src_totaltime ,
" src_time " : src_time ,
" fuel_totaltime " : fuel_totaltime ,
" fuel_time " : fuel_time }
inventory = { " fuel " : ( 0 , [ MTItemStack ( ) ] ) ,
" src " : ( 0 , [ MTItemStack ( ) ] ) ,
" dst " : ( 0 , [ MTItemStack ( ) ] * 4 ) }
return None , None , ( fields , inventory )
2014-02-09 16:37:11 +00:00
2014-02-08 18:47:28 +00:00
def convert_sign ( te ) :
t = " "
for i in range ( 1 , 5 ) :
2015-11-19 07:40:01 +00:00
line = te . get ( " Text " + str ( i ) , " " ) . strip ( ' " ' )
2016-03-23 19:58:52 +00:00
if ' { " text " : " ' in line :
parts = line . split ( ' " ' )
line = parts [ 3 ]
2014-02-08 18:47:28 +00:00
if line != " " :
t + = line
2015-11-19 07:40:01 +00:00
t + = " \n "
2014-02-08 18:47:28 +00:00
t = t . strip ( )
2015-11-19 07:40:01 +00:00
fields = { " infotext " : t ,
2014-03-04 13:04:53 +00:00
" text " : t ,
2015-11-19 07:40:01 +00:00
" __signslib_new_format " : " 1 " ,
" formspec " : " size[6,4]textarea[0,-0.3;6.5,3;text;;$ {text} ]button_exit[2,3.4;2,1;ok;Write]background[-0.5,-0.5;7,5;bg_signs_lib.jpg] " }
2014-03-04 13:04:53 +00:00
return None , None , ( fields , { } )
2014-02-08 18:47:28 +00:00
2015-11-21 07:47:15 +00:00
def convert_nodeblock ( te ) :
pitch = te . get ( " note " )
2015-11-21 22:55:40 +00:00
return None , int ( pitch ) % 12 , None
2015-11-21 07:47:15 +00:00
2015-11-22 22:47:28 +00:00
def convert_pot ( te ) :
c = str ( te . get ( " Item " ) ) + " : " + str ( te . get ( " Data " ) )
# translation table for flowers
# highly approximate, based on color only
t = {
2017-02-23 06:37:41 +00:00
" minecraft:air:0 " : 0 ,
2015-11-22 22:47:28 +00:00
" minecraft:brown_mushroom:0 " : 1 ,
" minecraft:red_mushroom:0 " : 2 ,
" minecraft:cactus:0 " : 3 ,
" minecraft:deadbush:0 " : 4 ,
" minecraft:red_flower:0 " : 5 ,
" minecraft:red_flower:1 " : 6 ,
" minecraft:red_flower:2 " : 7 ,
" minecraft:red_flower:3 " : 8 ,
" minecraft:red_flower:4 " : 9 ,
" minecraft:red_flower:5 " : 10 ,
" minecraft:red_flower:6 " : 11 ,
" minecraft:red_flower:7 " : 12 ,
" minecraft:red_flower:8 " : 13 ,
" minecraft:sapling:0 " : 14 ,
" minecraft:sapling:1 " : 15 ,
" minecraft:sapling:2 " : 16 ,
" minecraft:sapling:3 " : 17 ,
" minecraft:sapling:4 " : 18 ,
" minecraft:sapling:5 " : 19 ,
" minecraft:tallgrass:2 " : 20 ,
" minecraft:yellow_flower:0 " : 21
}
try :
fields = { " _plant " : t [ c ] }
return None , None , ( fields , { } )
except :
2016-08-18 08:40:15 +00:00
logger . warning ( ' Unknown flower pot type: ' + c )
2015-11-22 22:47:28 +00:00
return None , None , None
2015-11-23 06:04:31 +00:00
def convert_cmdblock ( te ) :
c = te . get ( " Command " )
c = c . replace ( " /tp " , " teleport " )
c = c . replace ( " /tell " , " tell " )
c = c . replace ( " @p " , " @nearest " )
c = c . replace ( " @r " , " @random " )
2016-08-24 11:17:42 +00:00
m = re . search ( ' \ /time set ( \ d+) ' , c )
if m :
t = ( int ( m . group ( 1 ) ) + 6000 ) % 24000
c = c . replace ( m . group ( 0 ) , " time %d " % t )
logger . info ( " replacing command: ' %s ' by ' %s ' " , m . group ( 0 ) , ( " time %d " % t ) )
logger . info ( " command block: ' %s ' " , c )
2015-11-23 06:04:31 +00:00
fields = { " infotext " : " Command block, commands: \" " + c + " \" " ,
" commands " : c ,
" owner " : " no owner " ,
" formspec " : " invsize[9,5;]textarea[0.5,0.5;8.5,4;commands;Commands; " + c + " ]label[1,3.8;@nearest, @farthest, and @random are replaced by the respective player names]button_exit[3.3,4.5;2,1;submit;Submit] "
}
return None , None , ( fields , { } )
2017-02-23 06:37:41 +00:00
te_convert = { " minecraft:chest " : convert_chest ,
" minecraft:sign " : convert_sign ,
" minecraft:furnace " : convert_furnace ,
2017-02-23 06:47:39 +00:00
" minecraft:noteblock " : convert_nodeblock ,
2017-02-23 06:37:41 +00:00
" minecraft:flower_pot " : convert_pot ,
" minecraft:command_block " : convert_cmdblock }