localp={}
localcomp_up={
}
localcomp_until={
}
localver_up="none"
-- Geral components
localbasic={
attribute_modifiers={
},
break_sound="minecraft:entity.item.break",
enchantments={
},
lore={
},
max_stack_size=64,
rarity="common",
repair_cost=0,
swing_animation={
},
tooltip_display={
},
use_effects={
},
item_model="minecraft:air",
item_name={
translate="item.minecraft.air",
}
}
-- Types
localcomponentTypes={
_type="compound",
aa={
_type="special",
},
aab={
_type="special",
},
death_protection={
_type="compound",
death_effects={
_type="list",
_children={
effects={
_type="list",
_children={
id="string",
amplifier="byte",
show_icon="bool",
duration="int"
},
},
type="string",
},
}
},
attack_range={
_type="compound",
min_reach="float",
max_reach="float",
hitbox_margin="float",
max_creative_reach="float",
mob_factor="float",
min_creative_reach="float",
},
kinetic_weapon={
_type="compound",
dismount_conditions={
min_speed="float",
_type="compound",
max_duration_ticks="int"
},
knockback_conditions={
min_speed="float",
_type="compound",
max_duration_ticks="int"
},
damage_conditions={
min_relative_speed="float",
_type="compound",
max_duration_ticks="int"
},
sound="string",
hit_sound="string",
damage_multiplier="float",
forward_movement="float",
delay_ticks="int",
},
piercing_weapon={
_type="compound",
hit_sound="string",
sound="string",
},
enchantments={
_type="compound",
},
equippable={
_type="compound",
slot="string",
equip_sound="string",
asset_id="string",
allowed_entities="string",
allowed_entities_l={--!! allowed_entities
_type="slist",
},
dispensable="bool",
swappable="bool",
equip_on_interact="bool",
camera_overlay="string",
can_be_sheared="bool",
shearing_sound="string"
},
food={
_type="compound",
saturation="float",
nutrition="int",
can_always_eat="bool"
},
lore={
_type="list",
},
use_effects={
_type="compound",
interact_vibrations="bool",
can_sprint="bool",
speed_multiplier="float",
},
tooltip_display={
_type="compound",
},
swing_animation={
_type="compound",
duration="int",
type="string"
},
item_name={
_type="compound",
translate="string",
},
tool={
_type="compound",
default_mining_speed="float",
damage_per_block="int",
can_destroy_blocks_in_creative="bool",
rules={
_type="list",
_children={
blocks="string",
speed="float",
correct_for_drops="bool"
}
}
},
enchantable={
_type="compound",
value="int"
},
repairable={
_type="compound",
items="string"
},
weapon={
_type="compound",
item_damage_per_attack="int",
disable_blocking_for_seconds="float",
},
consumable={
_type="compound",
has_consume_particles="bool",
sound="string",
animation="string",
on_consume_effects={
_type="list",
_children={
effects={
_type="list",
_children={
id="string",
amplifier="byte",
show_icon="bool",
duration="int"
},
},
type="string",
},
},
},
use_remainder={
_type="compound",
id="string",
count="int"
},
use_cooldown={
_type="compound",
seconds="float",
},
fireworks={
_type="compound",
flight_duration="byte"
},
writable_book_content={
_type="compound",
},
potion_contents={
_type="compound",
},
bucket_entity_data={
_type="compound",
},
block_state={
_type="compound",
},
glider={
_type="compound",
},
stored_enchantments={
_type="compound",
},
map_decorations={
_type="compound",
},
entity_data={
_type="compound",
id="string"
},
damage_resistant={
_type="compound",
types="string"
},
blocks_attacks={
_type="compound",
item_damage={
_type="compound",
threshold="float",
factor="float",
base="float",
},
bypassed_by="string",
disabled_sound="string",
block_sound="string",
block_delay_seconds="float"
},
attribute_modifiers={
_type="list",
_children={
type="string",
id="string",
slot="string",
operation="string",
amount="float",
display={
_type="compound",
type="string"
},
}
},
bees={
_type="list"
},
bundle_contents={
_type="list"
},
container={
_type="list"
},
banner_patterns={
_type="list"
},
charged_projectiles={
_type="list"
},
pot_decorations={
_type="slist"
},
rarity="string",
item_model="string",
break_sound="string",
damage_type="string",
jukebox_playable="string",
dye="string",
instrument="string",
provides_trim_material="string",
chicken_variant="string",--!! chicken/variant
damage="int",
max_damage="int",
repair_cost="int",
max_stack_size="int",
map_color="int",
minimum_attack_charge="float",
enchantment_glint_override="bool",
}
localtd=":"
localtdc=": <div class='mw-collapsible'>"
localtext=""
-- Function type-tostring
localfunctionttostring(typ,v,style,lineend,frame)
n=string.find(tostring(name),"@")
ifnthen
returnttostring(typ,string.sub(tostring(v),0,n-1),style,-1,frame).."/"..ttostring(typ,string.sub(tostring(v),n+1),style,lineend,frame)
end
iflineendthen
iflineend==-1then
cm=""
else
cm=style.dotor""
end
else
cm=style.commaor""
end
ifstring.find(tostring(v),"||")then
localaux=''
localutp=''
aux=string.gsub(tostring(v),'||until','')
ifnot(aux==tostring(v))then
utp=style.tempuntil
v=aux
end
aux=string.gsub(tostring(v),'||upcoming','')
ifnot(aux==tostring(v))then
utp=style.tempup
v=aux
end
cm=utp..cm
end
tv=style.tv
iftyp=="string"then
returnframe:expandTemplate{title=tv,args={'"'..tostring(v)..'"',nbt_type=typ,raw_vaule=v}}..cm
elseiftyp=="float"then
localstr=tostring(v)
ifnotstr:find("%.")then
returnframe:expandTemplate{title=tv,args={string.format("%.1f",v).."f",nbt_type=typ,raw_vaule=v}}..cm
else
returnframe:expandTemplate{title=tv,args={str.."f",nbt_type=typ,raw_vaule=v}}..cm
end
elseiftyp=="byte"then
returnframe:expandTemplate{title=tv,args={tostring(v).."b",nbt_type=typ,raw_vaule=v}}..cm
else
returnframe:expandTemplate{title=tv,args={tostring(v),nbt_type=typ,raw_vaule=v}}..cm
end
end
-- Componante name style
localfunctioncnamestyle(style,name)
n=string.find(tostring(name),"@")
ifnthen
returncnamestyle(style,string.sub(tostring(name),0,n-1)).."/"..cnamestyle(style,string.sub(tostring(name),n+1))
end
ifstyle.c[name]==nilandbasic[name]==nilthen
ifstring.find(tostring(name),"||")then
localaux=''
localutp=''
aux=string.gsub(tostring(name),'||until','')
ifnot(aux==tostring(name))then
utp=style.tempuntil
name=aux
end
aux=string.gsub(tostring(name),'||upcoming','')
ifnot(aux==tostring(name))then
utp=style.tempup
name=aux
end
name=name..utp..cm
end
returnname
end
ifname=="chicken_variant"then
name="chicken/variant"
end
localret=name
ifstyle.minecraftthen
ret="minecraft:"..name
end
ifstyle.linkthen
ret="[[Data_component#"..name.."|"..ret.."]]"
end
returnret..(style.unup[name]or"")
end
-- Function sorted
localfunctionsortedKeys(t)
localkeys={}
forkinpairs(tor{})do
table.insert(keys,k)
end
table.sort(keys)
returnkeys
end
-- Function recursive
localfunctionrenderTree(frame,tbl,typetree,depth,name,debugMode,style,LE)
depth=depthor1
localout={}
iftypetreeandtypetree._type=="list"then
table.insert(out,string.rep("*",depth)..
(debugModeand"{{nbt|list|"..(cnamestyle(style,name)or"").."}}:"orframe:expandTemplate{title="nbt",args={"list",cnamestyle(style,name)}}..":"))
localnone=true
for_,elementinipairs(tblor{})do
none=false
--listu = (not typetree.unup or not typetree.unup[_]) and "" or (typetree.unup[_]==un and style.tempuntil) or (typetree.unup[_]==un and style.tempunp) or ""
table.insert(out,string.rep("*",depth+1)..
(debugModeand"{{nbt|compound}}:"orframe:expandTemplate{title="nbt",args={"compound"}}..":"))
-- ":" -> listu..":"
localselement=sortedKeys(element)
for_,kinipairs(selement)do
localv=element[k]
localle=_==#selementandLE
localsubtype=(typetree._childrenandtypetree._children[k])or"a"
iftype(v)=="table"andtype(subtype)=="table"then
table.insert(out,renderTree(frame,v,subtype,depth+2,k,debugMode,style,le))
else
localline=string.rep("*",depth+2)..
(debugModeand"{{nbt|"..subtype.."|"..k.."}}: "..ttostring(subtype,v,style,le.frame)
orframe:expandTemplate{title="nbt",args={subtype,k}}..": "..ttostring(subtype,v,style,le,frame))
table.insert(out,line)
end
end
end
ifnonethen
ifLEand(style.none)and(style.comma)and(style.dot)then
localnonedot=style.none:gsub("(.*)"..style.comma,"%1"..style.dot)
table.insert(out,nonedot)
else
table.insert(out,style.none)
end
returntable.concat(out)
end
returntable.concat(out,"\n")
end
iftypetreeand(typetree._type=="compound"ortypetree._type=="special")then
ifname=="components"then
td=tdc
else
td=":"
end
-- if name == "aa" then
iftypetree._type=="special"then
table.insert(out,string.rep("*",depth)..'<li class="treeview-header nbttree-inherited load-page">'..
style.basic[name]..'</li><li class="treeview-header nbttree-inherited mw-collapsible '..
(style.bc[name]and''or'mw-collapsed')..'" data-treeview="true" data-treeviewclass="nbttree-inherited" style="font-weight: normal;">')
else
table.insert(out,string.rep("*",depth)..
(debugModeand"{{nbt|compound|"..(cnamestyle(style,name)or"").."}}"..tdorframe:expandTemplate{title="nbt",args={"compound",cnamestyle(style,name)}}..td))
end
localnone=true
localstbl=sortedKeys(tbl)
for_,kinipairs(stbl)do
le=(_==#stbl)andLE
none=false
localv=tbl[k]
localsubtype=typetree[k]or((name=="block_state")and"string"or"a")
iftype(v)=="table"andtype(subtype)=="table"then
table.insert(out,renderTree(frame,v,subtype,depth+1,k,debugMode,style,le))
else
localline=string.rep("*",depth+1)..
(debugModeand"{{nbt|"..subtype.."|"..cnamestyle(style,k).."}}: "..ttostring(subtype,v,style,le,frame)
orframe:expandTemplate{title="nbt",args={subtype,cnamestyle(style,k)}}..": "..ttostring(subtype,v,style,le,frame))
table.insert(out,line)
end
end
ifnonethen
ifLEand(style.none)and(style.comma)and(style.dot)then
localnonedot=style.none:gsub("(.*)"..style.comma,"%1"..style.dot)
table.insert(out,nonedot)
else
table.insert(out,style.none)
end
ifname==style.tend.aaorname==style.tend.aabthen
table.insert(out,"</li>")
end
returntable.concat(out)
end
returntable.concat(out,"\n")
end
iftypetreeandtypetree._type=="slist"then
ifname=="allowed_entities_l"then
name="allowed_entities"
end
table.insert(out,string.rep("*",depth)..
(debugModeand"{{nbt|list|"..(cnamestyle(style,name)or"").."}}:"orframe:expandTemplate{title="nbt",args={"list",cnamestyle(style,name)}}..":"))
localstbl=sortedKeys(tbl)
for_,kinipairs(stbl)do
localle=_==#stblandLE
localv=tbl[k]
localsubtype="string"
localline=string.rep("*",depth+1)..
(debugModeand"{{nbt|"..subtype.."}}: "..ttostring(subtype,v,style,le,frame)
orframe:expandTemplate{title="nbt",args={subtype}}..": "..ttostring(subtype,v,style,le,frame))
table.insert(out,line)
end
returntable.concat(out,"\n")
end
return""
end
functionp.component(frame)
localid=frame.args.id
id=string.gsub(string.gsub(string.lower(tostring(id)),"minecraft:","")," ","_")
-- id = <teste> --!!! NOT SALVE
text=frame.args.text
localdebug=frame.args.debug=="true"
localsmall=not(frame.args.small=="false")
localcollapsed=not(frame.args.collapsed=="false")
localsrcitem=mw.loadData("Module:Default_data_component/items")[id]
ifnotsrcitemornotsrcitem.cthen
returnframe:expandTemplate{title="nbt",args={"A","Module error"}}..": "..id.." is an invalid ID. See [[Java Edition data values/Items]] or [[Java Edition data values/Blocks]]"
end
localitem={c={}}
fork,vinpairs(srcitem.c)do
item.c[k]=v
end
localnbc=(tonumber(frame.args.basiccollapsed)or0)
localstyle={
minecraft=frame.args.minecraft=="true",
link=frame.args.link=="true",
none=frame.args.none,
comma=frame.args.comma,
basic={
aa=frame.args.basic,
aab=frame.args.basic2
},
bc={
aa=nbc%2==1,
aab=math.floor(nbc/2)%2==1
},
dot=frame.args.dot,
c={},
tend={},
tempuntil=frame:expandTemplate{title="until",args={ver_up}},
tempup=frame:expandTemplate{title="upcoming",args={ver_up}},
unup={}
}
for_,compinipairs(comp_up)do
style.unup[comp]=style.tempup
end
forcompinipairs(comp_until)do
style.unup[comp]=style.tempuntil
end
ifstyle.none==nilthen
style.none=""
end
iftext==nilthen
text=""
else
text=string.gsub(text,"%(%%id%)",id)
end
ifstyle.comma==nilthen
style.comma=""
end
ifstyle.tv==nilthen
style.tv="cd"
end
-- Tests
-- style.none = " ''none''"
-- text = " the item's defaut '''components'''"
-- style.comma = ","
-- style.basic.aa = "Basic components"
-- style.dot = "."
ifcollapsedthen
ifdebugthen
tdc=":"..text.." (div class='mw-collapsible mw-collapsed')"
else
tdc=":"..text.." <div class='mw-collapsible mw-collapsed'>"
end
elseifdebugthen
tdc=":"..text.." (div class='mw-collapsible')"
else
tdc=":"..text.." <div class='mw-collapsible>"
end
ifstyle.basic.aaandnot(style.basic.aa=="")then
else
style.basic.aa="Basic components:"
end
ifstyle.basic.aabandnot(style.basic.aab=="")then
else
style.basic.aab="nil"
end
--style.basic.aa = 'nil'
ifnot(style.basic.aa=='nil')ornot(style.basic.aab=='nil')ornotsmallthen
for_,kinpairs(sortedKeys(basic))do
ifitem.c[k]==nilthen
ifsmallthen
elseifnot(style.basic.aa=='nil')then
item.c.aa=item.c.aaor{}
item.c.aa[k]=basic[k]
componentTypes.aa[k]=componentTypes[k]
style.tend.aa=k
else
item.c[k]=basic[k]
end
elseifnot(style.basic.aab=='nil')then
item.c.aab=item.c.aabor{}
item.c.aab[k]=item.c[k]
componentTypes.aab[k]=componentTypes[k]
style.tend.aab=k
item.c[k]=nil
end
end
end
style.c=item.c
ifdebugthen
return'<nowiki> (div class="treeview")\n'..
renderTree(frame,item.c,componentTypes,1,"components",true,style,true)..
'\n(/div)(/div) </nowiki>'
else
return'<div class="treeview">\n'..
renderTree(frame,item.c,componentTypes,1,"components",false,style,true)..
'\n</div></div>'
end
end
functionp.show(frame)
returnp.component(frame)
end
returnp