diff --git a/README.md b/README.md index 863baa8..fcda411 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,35 @@ # Easy GUI -under this repos, run commands below + +## Environment +This repos only use the package `pyyaml`, see `requirements.txt` ```bat -conda create --name easy_gui -conda activate easy_gui pip install pyyaml -python -m easy_gui example.yaml ``` -create pack.mcmeta and data automatically \ No newline at end of file +### execute +Download release file to run (recommended for user) +``` +python ./easy_GUI.zip ./your_container_settings.yaml +``` +Or you can just run under this repos (recommended for developer) +``` +python ./easy_GUI/ ./your_container_settings.yaml +``` +It create `pack.mcmeta` and `data` in root automatically +## Examples +Here are some examples setting files, it's easy to understand. +* drop to summon GUI block (type = `drop`) +[backpack.yaml](/example/backpack.yaml) +* spawn egg to summon GUI block (type = `spawn_egg`) +[scribing_table.yaml](/example/scribing_table.yaml) +[working_table.yaml](/example/working_table.yaml) +## Tutorual +[tutorial.md](/tutorial.md) +## License +You can use this tool to generate your datapack. +You can fork this repos and modify the tool to your version. +You can do antything with it. +Credit on me if you use this tool. (let your user know I make this and let more people know the tool). + +## Works on PMC +* [upgradable backpack](https://www.planetminecraft.com/data-pack/backpack-1-18-2/) +* [custom craft](https://www.planetminecraft.com/data-pack/better-anvil/) \ No newline at end of file diff --git a/backpack.yaml b/backpack.yaml deleted file mode 100644 index 6993514..0000000 --- a/backpack.yaml +++ /dev/null @@ -1,36 +0,0 @@ -id: backpack - -dropped_item: - id: leather_chestplate - text: Backpack - enchant: false - tag: {Unbreakable: 1b, HideFlags: 127, AttributeModifiers: []} - -load: 'function backpack:on/load' -destroy: 'function backpack:on/destroy' -setblock: replace - -entity: - block: - id: barrel - text: Backpack - item: - id: dirt - text: Backpack - -slot: - 0..8,18..25: - type: label - item: - id: black_stained_glass_pane - 26: - type: label - item: - id: barrier - text: Close - color: red - click: 'function eg:tile/backpack/destroy' - 9..17: - type: drop - cond: if - data: 'eg' \ No newline at end of file diff --git a/big_backpack.yaml b/big_backpack.yaml deleted file mode 100644 index 116fa1d..0000000 --- a/big_backpack.yaml +++ /dev/null @@ -1,36 +0,0 @@ -id: big_backpack - -dropped_item: - id: leather_chestplate - text: Backpack - enchant: false - tag: {Unbreakable: 1b, HideFlags: 127, AttributeModifiers: []} - -load: 'function backpack:on/load' -destroy: 'function backpack:on/destroy' -setblock: replace - -entity: - block: - id: barrel - text: Backpack - item: - id: dirt - text: Backpack - -slot: - 18..25: - type: label - item: - id: black_stained_glass_pane - 26: - type: label - item: - id: barrier - text: Close - color: red - click: 'function eg:tile/backpack/destroy' - 0..17: - type: drop - cond: if - data: 'eg' \ No newline at end of file diff --git a/drop_item.yaml b/drop_item.yaml deleted file mode 100644 index 3686be4..0000000 --- a/drop_item.yaml +++ /dev/null @@ -1,40 +0,0 @@ -id: example - -dropped_item: - id: dirt - text: Example GUI - enchant: true - color: dark_purple - tag: {Unbreakable: true, HideFlags: 127, AttributeModifiers: '[]'} - -destroy: say bye -load: say hi - -entity: - block: - id: dispenser - text: Example GUI - enchant: true - color: dark_purple - item: - id: writable_book - text: Example GUI - enchant: true - color: dark_purple - -slot: - 0..2,6..8: - type: label - item: - id: black_stained_glass_pane - 3,5: - type: n_left - n: 1 - 4: - type: label - item: - id: feather - enchant: true - text: Scribe ! - color: yellow - click: 'function #scribing_table:scribe' \ No newline at end of file diff --git a/easy_gui/__main__.py b/easy_gui/__main__.py index f69417c..4306c74 100644 --- a/easy_gui/__main__.py +++ b/easy_gui/__main__.py @@ -5,19 +5,91 @@ import json from zipfile import ZipFile from os import path +class Tag: + @staticmethod + def parse_list_to_str(data:list)->str: + if len(data)==0: + return '[]' + ret='[' + for item in data: + if isinstance(item,list): + ret+=Tag.parse_list_to_str(item)+',' + elif isinstance(item,dict): + ret+=Tag.parse_dict_to_str(item)+',' + elif isinstance(item,str): + ret+=f'"{item}",' + elif isinstance(item,bool): + ret+=f"{str(item).lower()}," + else: + ret+=item+',' + return ret[:-1]+']' + @staticmethod + def parse_dict_to_str(data:dict)->str: + if len(data)==0: + return '{}' + ret='{' + for k,v in data.items(): + if isinstance(v,list): + ret+=f"'{k}':{Tag.parse_list_to_str(v)}," + elif isinstance(v,dict): + ret+=f"'{k}':{Tag.parse_dict_to_str(v)}," + elif isinstance(v,str): + ret+=f"'{k}':'{v}'," + elif isinstance(v,bool): + ret+=f"'{k}':{str(v).lower()}," + else: + ret+=f"'{k}':{v}," + return ret[:-1]+'}' + @staticmethod + def parse(data:dict)->str: + ret='' + for k,v in data.items(): + if isinstance(v,list): + ret+=f",'{k}':{Tag.parse_list_to_str(v)}" + elif isinstance(v,dict): + ret+=f",'{k}':{Tag.parse_dict_to_str(v)}" + elif isinstance(v,str): + ret+=f",'{k}':'{v}'" + elif isinstance(v,bool): + ret+=f",'{k}':{str(v).lower()}" + else: + ret+=f",'{k}':{v}" + return ret[1:] + +class Display: + @staticmethod + def parse_jsontext(data:dict)->str: + if len(data)==0: + return '{}' + ret='{' + for k,v in data.items(): + if isinstance(v,str): + ret+=f'"{k}":"{v}",' + elif isinstance(v,bool): + ret+=f'"{k}":{str(v).lower()},' + else: + ret+=f'"{k}":{v},' + return ret[:-1]+'}' + @staticmethod + def parse_lore(lore:list)->list[str]: + ret=[] + for item in lore: + ret.append(Display.parse_jsontext(item)+',') + return ret + @staticmethod + def parse(data:dict) -> None: + if 'Name' in data: + data['Name']=Display.parse_jsontext(data['Name']) + else: + data['Name']='' + data["Lore"]= Display.parse_lore(data.get('Lore',[])) def template(code: str, pattern: dict[str, int | str]) -> str: for k, v in pattern.items(): code = code.replace(f'<{k}>', str(v)) return code -def tag_gen(data:dict): - tag = '' - for k, v in data.items(): - tag += f',{k}:{v}' - return tag - def write_code(code: str, filename: str) -> None: dirname = path.dirname(filename) if len(dirname) > 0: @@ -49,11 +121,26 @@ def update_values(new_values: set, filename: str) -> None: class Item: def __init__(self, data: dict) -> None: self.id = data['id'] - self.enchant = data.get('enchant', False) - self.text = data.get('text', '') - self.color = data.get('color', None) self.tag = data.get('tag', {}) - + if not isinstance(self.tag,dict): + exit('The tag of the item must be dictionary.') + if 'display' not in self.tag: + self.tag['display']={} + if not isinstance(self.tag['display'],dict): + exit('item.tag.display need to be a dict') + Display.parse(self.tag['display']) + self.Name = self.tag['display']['Name'] + self.tag:str = Tag.parse(self.tag) + +class Block: + def __init__(self,data:dict) -> None: + self.id = data['id'] + self.tag = data.get('tag', {}) + if not isinstance(self.tag,dict): + exit('The tag of the item must be dictionary.') + self.tag['CustomName']=Display.parse_jsontext(self.tag.get('CustomName',{})) + self.CustomName:str=self.tag['CustomName'] + self.tag:str=Tag.parse_dict_to_str(self.tag) class Slot: LABEL_ENTRY = get_resource('template/slot_type/label/entry.mcfunction') @@ -81,11 +168,8 @@ def codeGen(tile_id: str, slot: str | int, object: dict) -> tuple[str, str]: template(Slot.LABEL_EH, { 'slot': slot, 'item': item.id, - 'text': item.text, - 'color': f',"color":"{item.color}"' if item.color is not None else '', - 'enchant': ',Enchantments:[{id:"minecraft:binding_curse",lvl:1}]' if item.enchant else '', 'click': click, - 'tag': tag_gen(item.tag) + 'tag': f',{item.tag}' }) ) elif slot_type == 'n_left': @@ -103,7 +187,11 @@ def codeGen(tile_id: str, slot: str | int, object: dict) -> tuple[str, str]: ) elif slot_type == 'drop': cond: str = object.get('cond', 'undefined') - tag: str = object.get('tag', None) + tag=object.get('tag', None) + if isinstance(tag,dict): + tag: str = Tag.parse(tag) + elif tag is not None: + exit('tag must be dict in drop slot') data: str = object.get('data', None) item_id: str = object.get('id', None) if cond == 'if': @@ -162,13 +250,15 @@ def codeGen(tile_id: str, slot: str | int, object: dict) -> tuple[str, str]: data: dict = yaml.load(f, Loader=SafeLoader) tile_id = data['id'] -container_block = Item(data['entity']['block']) -container_item = Item(data['entity']['item']) -setblock = data.get('setblock', 'destroy') +block_id=data['block'] +itemtype=data['type'] entries = template(get_resource('template/tile/tick.mcfunction'), { "id": tile_id, - "block": container_block.id + "block": block_id }) +load_func = data.get('load', '') +destroy_func = data.get('destroy', '') +tick_func = data.get('tick', '') for slots, object in data['slot'].items(): slots = str(slots).split(',') for slot in slots: @@ -186,7 +276,7 @@ def codeGen(tile_id: str, slot: str | int, object: dict) -> tuple[str, str]: write_code( eh, f'data/eg/functions/tile/{tile_id}/slot/{slot}/eh.mcfunction') entries += entry -entries += data.get('tick', '') +entries += tick_func write_code(entries, f'data/eg/functions/tile/{tile_id}/tick.mcfunction') @@ -195,26 +285,20 @@ def codeGen(tile_id: str, slot: str | int, object: dict) -> tuple[str, str]: }), f'data/eg/functions/tile/{tile_id}/search/item_frame.mcfunction') -spawn_egg = data.get('spawn_egg', None) -if spawn_egg is not None: - spawn_egg = Item(spawn_egg) +container_item = Item(data.get('item', None)) +if itemtype == 'spawn_egg': write_code(template(get_resource('template/tile/spawn_egg.mcfunction'), { "id": tile_id, - 'spawn_egg': spawn_egg.id, - 'text': spawn_egg.text, - 'color': f',"color":"{spawn_egg.color}"' if spawn_egg.color is not None else '', - 'enchant': ',Enchantments:[{id:"minecraft:binding_curse",lvl:1}]' if spawn_egg.enchant else '', - 'tag': tag_gen(spawn_egg.tag) + 'spawn_egg': container_item.id, + 'tag':f',{container_item.tag}', + 'text':container_item.Name }), f'data/eg/functions/tile/{tile_id}/spawn_egg.mcfunction') write_code(template(get_resource('template/tile/spawn_egg.json'), { "id": tile_id, - 'spawn_egg': spawn_egg.id, - 'text': spawn_egg.text, - 'color': f',\\"color\\":\\"{spawn_egg.color}\\"' if spawn_egg.color is not None else '', - 'enchant': ',Enchantments:[{id:\\"minecraft:binding_curse\\",lvl:1}]' if spawn_egg.enchant else '', - 'tag': tag_gen(spawn_egg.tag) + 'spawn_egg': container_item.id, + 'tag': f',{container_item.tag}'.replace('"','\\"') }), f'data/eg/loot_tables/{tile_id}.json') @@ -223,9 +307,13 @@ def codeGen(tile_id: str, slot: str | int, object: dict) -> tuple[str, str]: }), f'data/eg/functions/tile/{tile_id}/search/area_effect_cloud.mcfunction') - write_code(template(get_resource(f'template/tile/destroy_{setblock}.mcfunction'), { + write_code(template(get_resource(f'template/tile/destroy.mcfunction'), { "id": tile_id, - "block": container_block.id + "block": block_id, + "text":container_item.Name, + "load":destroy_func, + "tag":f',{container_item.tag}', + "spawn_egg":container_item.id }), f'data/eg/functions/tile/{tile_id}/destroy.mcfunction') @@ -242,37 +330,19 @@ def codeGen(tile_id: str, slot: str | int, object: dict) -> tuple[str, str]: update_values({f"eg:tile/{tile_id}/search/area_effect_cloud"}, 'data/eg/tags/functions/search/area_effect_cloud.json') - write_code(template(get_resource('template/tile/try_spawn/load.mcfunction'), { - "id": tile_id, - 'item': container_item.id, - 'item_text': container_item.text, - 'item_color': f',"color":"{container_item.color}"' if container_item.color is not None else '', - 'item_enchant': ',Enchantments:[{id:"minecraft:binding_curse",lvl:1}]' if container_item.enchant else '', - 'item_tag': tag_gen(container_item.tag), - 'block': container_block.id, - 'block_text': container_block.text, - 'block_color': f',"color":"{container_block.color}"' if container_block.color is not None else '' - }), - f'data/eg/functions/tile/{tile_id}/try_spawn/load.mcfunction') -else: - dropped_item = Item(data['dropped_item']) +elif itemtype == 'drop': write_code(template(get_resource('template/tile_dropped_item/dropped_item.mcfunction'), { "id": tile_id, - 'item': dropped_item.id, - 'text': dropped_item.text, - 'color': f',"color":"{dropped_item.color}"' if dropped_item.color is not None else '', - 'enchant': ',Enchantments:[{id:"minecraft:binding_curse",lvl:1}]' if dropped_item.enchant else '', - 'tag': tag_gen(dropped_item.tag) + 'item': container_item.id, + 'text': container_item.Name, + 'tag': f',{container_item.tag}' }), f'data/eg/functions/tile/{tile_id}/dropped_item.mcfunction') write_code(template(get_resource('template/tile_dropped_item/dropped_item.json'), { "id": tile_id, - 'item': dropped_item.id, - 'text': dropped_item.text, - 'color': f',\\"color\\":\\"{dropped_item.color}\\"' if dropped_item.color is not None else '', - 'enchant': ',Enchantments:[{id:\\"minecraft:binding_curse\\",lvl:1}]' if dropped_item.enchant else '', - 'tag': tag_gen(dropped_item.tag) + 'item': container_item.id, + 'tag': f',{container_item.tag}'.replace('"','\\"') }), f'data/eg/loot_tables/{tile_id}.json') @@ -281,16 +351,14 @@ def codeGen(tile_id: str, slot: str | int, object: dict) -> tuple[str, str]: }), f'data/eg/functions/tile/{tile_id}/search/item.mcfunction') - destroy = data.get('destroy', None) - write_code(template(get_resource(f'template/tile_dropped_item/destroy_{setblock}.mcfunction'), { + + write_code(template(get_resource(f'template/tile_dropped_item/destroy.mcfunction'), { "id": tile_id, - "block": container_block.id, - 'load': f'execute positioned ~ ~-1 ~ run {destroy}' if destroy is not None else '', - 'item': dropped_item.id, - 'text': dropped_item.text, - 'color': f',"color":"{dropped_item.color}"' if dropped_item.color is not None else '', - 'enchant': ',Enchantments:[{id:"minecraft:binding_curse",lvl:1}]' if dropped_item.enchant else '', - 'tag': tag_gen(dropped_item.tag) + "block": block_id, + 'load': destroy_func, + 'item': container_item.id, + "text":container_item.Name, + 'tag': f',{container_item.tag}' }), f'data/eg/functions/tile/{tile_id}/destroy.mcfunction') @@ -301,19 +369,16 @@ def codeGen(tile_id: str, slot: str | int, object: dict) -> tuple[str, str]: update_values({f"eg:tile/{tile_id}/search/item"}, 'data/eg/tags/functions/search/item.json') +else: + exit('type can only be drop or spawn_egg') - load = data.get('load', None) - write_code(template(get_resource('template/tile_dropped_item/try_spawn/load.mcfunction'), { - 'load': f'execute positioned ~ ~1 ~ run {load}' if load is not None else '', +write_code(template(get_resource('template/tile/try_spawn/load.mcfunction'), { + 'load': load_func, "id": tile_id, 'item': container_item.id, - 'item_text': container_item.text, - 'item_color': f',"color":"{container_item.color}"' if container_item.color is not None else '', - 'item_enchant': ',Enchantments:[{id:"minecraft:binding_curse",lvl:1}]' if container_item.enchant else '', - 'item_tag': tag_gen(container_item.tag), - 'block': container_block.id, - 'block_text': container_block.text, - 'block_color': f',"color":"{container_block.color}"' if container_block.color is not None else '' + 'tag': container_item.tag, + 'block': block_id, + 'text': container_item.Name, }), f'data/eg/functions/tile/{tile_id}/try_spawn/load.mcfunction') diff --git a/easy_gui/template/slot_type/label/eh.mcfunction b/easy_gui/template/slot_type/label/eh.mcfunction index 43ef628..d6c7c32 100644 --- a/easy_gui/template/slot_type/label/eh.mcfunction +++ b/easy_gui/template/slot_type/label/eh.mcfunction @@ -1,5 +1,5 @@ summon item ~ ~1 ~ {Motion:[0.0,0.3,0.0],Item:{id:"minecraft:cookie",Count:1b,tag:{eg:{is:1b,type:label}}},Tags:[egno]} execute positioned ~ ~1 ~ run data modify entity @e[type=item,sort=nearest,limit=1,nbt={Item:{tag:{eg:{is:1b,type:label}}}}] Item set from block ~ ~-1 ~ Items[{Slot:b}] -item replace block ~ ~ ~ container. with {eg:{is:1b,type:label},HideFlags:1,display:{Name:'{"text": "","italic":false}'}} 1 +item replace block ~ ~ ~ container. with {eg:{is:1b,type:label}} 1 playsound block.dispenser.dispense ambient @a ~ ~ ~ \ No newline at end of file diff --git a/easy_gui/template/tile/destroy.mcfunction b/easy_gui/template/tile/destroy.mcfunction new file mode 100644 index 0000000..1cdd771 --- /dev/null +++ b/easy_gui/template/tile/destroy.mcfunction @@ -0,0 +1,6 @@ +summon item ~ ~ ~ {Tags:[egset],CustomNameVisible:1b,CustomName:'',Motion:[0.0,0.3,0.0],Item:{Count:1b,id:"",tag:{EntityTag:{id:"minecraft:area_effect_cloud",Tags:[eg.]}}}} + +tag @e[sort=nearest,limit=1,type=item,tag=egset] remove egset +kill @s +setblock ~ ~ ~ air destroy +kill @e[type=item,nbt={Item:{id:"",Count:1b}},distance=..1,sort=nearest] \ No newline at end of file diff --git a/easy_gui/template/tile/destroy_destroy.mcfunction b/easy_gui/template/tile/destroy_destroy.mcfunction deleted file mode 100644 index 1985d18..0000000 --- a/easy_gui/template/tile/destroy_destroy.mcfunction +++ /dev/null @@ -1,4 +0,0 @@ -kill @s -setblock ~ ~ ~ air destroy -kill @e[type=item,nbt={Item:{id:"",Count:1b}},distance=..1,sort=nearest] -function eg:tile//spawn_egg diff --git a/easy_gui/template/tile/destroy_replace.mcfunction b/easy_gui/template/tile/destroy_replace.mcfunction deleted file mode 100644 index 23141e4..0000000 --- a/easy_gui/template/tile/destroy_replace.mcfunction +++ /dev/null @@ -1,3 +0,0 @@ -kill @s -setblock ~ ~ ~ air replace -function eg:tile//spawn_egg diff --git a/easy_gui/template/tile/spawn_egg.json b/easy_gui/template/tile/spawn_egg.json index 076fd88..2bdf121 100644 --- a/easy_gui/template/tile/spawn_egg.json +++ b/easy_gui/template/tile/spawn_egg.json @@ -6,11 +6,11 @@ "entries": [ { "type":"item", - "name": "_spawn_egg", + "name": "", "functions": [ { "function":"set_nbt", - "tag": "{HideFlags:1,display:{Name:'{\"text\":\"\",\"italic\":false}'},EntityTag:{id:\"minecraft:area_effect_cloud\",Tags:[eg.]}}" + "tag": "{EntityTag:{id:\"minecraft:area_effect_cloud\",Tags:[eg.]}}" } ] } diff --git a/easy_gui/template/tile/spawn_egg.mcfunction b/easy_gui/template/tile/spawn_egg.mcfunction index b12f314..6ac6d74 100644 --- a/easy_gui/template/tile/spawn_egg.mcfunction +++ b/easy_gui/template/tile/spawn_egg.mcfunction @@ -1 +1 @@ -summon item ~ ~ ~ {CustomNameVisible:1b,CustomName:'{"text":"","italic":false}',Motion:[0.0,0.3,0.0],Item:{Count:1b,id:"_spawn_egg",tag:{display:{Name:'{"text":"","italic":false}'},EntityTag:{id:"minecraft:area_effect_cloud",Tags:[eg.]},HideFlags:1}}} \ No newline at end of file +summon item ~ ~ ~ {CustomNameVisible:1b,CustomName:'',Motion:[0.0,0.3,0.0],Item:{Count:1b,id:"",tag:{EntityTag:{id:"minecraft:area_effect_cloud",Tags:[eg.]}}}} \ No newline at end of file diff --git a/easy_gui/template/tile/try_spawn/load.mcfunction b/easy_gui/template/tile/try_spawn/load.mcfunction index d9acc5c..eccbc58 100644 --- a/easy_gui/template/tile/try_spawn/load.mcfunction +++ b/easy_gui/template/tile/try_spawn/load.mcfunction @@ -1,3 +1,5 @@ +setblock ~ ~ ~ [facing=up]{CustomName:''} destroy +summon item_frame ~ ~ ~ {CustomName:'',Tags:[eg.,egset],Facing:1b,Item:{id:"",Count:1b,tag:{}},Invulnerable:1b,Fixed:1b,Invisible:1b} + kill @s -setblock ~ ~ ~ [facing=up]{CustomName:'{"text":"","italic":false}'} destroy -summon item_frame ~ ~ ~ {Tags:[eg.],Facing:1b,Item:{id:"",Count:1b,tag:{display:{Name:'{"text":"","italic":false}'},HideFlags:1}},Invulnerable:1b,Fixed:1b,Invisible:1b} \ No newline at end of file +tag @e[sort=nearest,limit=1,type=item_frame,tag=egset] remove egset diff --git a/easy_gui/template/tile_dropped_item/destroy.mcfunction b/easy_gui/template/tile_dropped_item/destroy.mcfunction new file mode 100644 index 0000000..2c43fea --- /dev/null +++ b/easy_gui/template/tile_dropped_item/destroy.mcfunction @@ -0,0 +1,6 @@ +summon item ~ ~ ~ {Tags:[egno,egset],CustomNameVisible:1b,CustomName:'',Motion:[0.0,0.3,0.0],Item:{Count:1b,id:"",tag:{eg:{is:1b,type:tile,name:}}}} + +tag @e[sort=nearest,limit=1,type=item,tag=egset] remove egset +kill @s +setblock ~ ~ ~ air destroy +kill @e[type=item,tag=!egno,nbt={Item:{id:"",Count:1b}},distance=..1,sort=nearest] \ No newline at end of file diff --git a/easy_gui/template/tile_dropped_item/destroy_destroy.mcfunction b/easy_gui/template/tile_dropped_item/destroy_destroy.mcfunction deleted file mode 100644 index a2cd4a4..0000000 --- a/easy_gui/template/tile_dropped_item/destroy_destroy.mcfunction +++ /dev/null @@ -1,6 +0,0 @@ -summon item ~ ~ ~ {Tags:[egno,egset],CustomNameVisible:1b,CustomName:'{"text":"","italic":false}',Motion:[0.0,0.3,0.0],Item:{Count:1b,id:"",tag:{display:{Name:'{"text":"","italic":false}'},eg:{is:1b,type:tile,name:}}}} - -kill @s -tag @e[sort=nearest,limit=1,type=item,tag=egset] remove egset -setblock ~ ~ ~ air destroy -kill @e[type=item,tag=!egno,nbt={Item:{id:"minecraft:",Count:1b}},distance=..1,sort=nearest] \ No newline at end of file diff --git a/easy_gui/template/tile_dropped_item/destroy_replace.mcfunction b/easy_gui/template/tile_dropped_item/destroy_replace.mcfunction deleted file mode 100644 index 6ccf54a..0000000 --- a/easy_gui/template/tile_dropped_item/destroy_replace.mcfunction +++ /dev/null @@ -1,5 +0,0 @@ -summon item ~ ~ ~ {Tags:[egno,egset],CustomNameVisible:1b,CustomName:'{"text":"","italic":false}',Motion:[0.0,0.3,0.0],Item:{Count:1b,id:"",tag:{display:{Name:'{"text":"","italic":false}'},eg:{is:1b,type:tile,name:}}}} - -kill @s -tag @e[sort=nearest,limit=1,type=item,tag=egset] remove egset -setblock ~ ~ ~ air replace \ No newline at end of file diff --git a/easy_gui/template/tile_dropped_item/dropped_item.json b/easy_gui/template/tile_dropped_item/dropped_item.json index 13b2ba8..aa6919a 100644 --- a/easy_gui/template/tile_dropped_item/dropped_item.json +++ b/easy_gui/template/tile_dropped_item/dropped_item.json @@ -10,7 +10,7 @@ "functions": [ { "function":"set_nbt", - "tag": "{display:{Name:'{\"text\":\"\",\"italic\":false}'},eg:{is:1b,type:tile,name:}}" + "tag": "{eg:{is:1b,type:tile,name:}}" } ] } diff --git a/easy_gui/template/tile_dropped_item/dropped_item.mcfunction b/easy_gui/template/tile_dropped_item/dropped_item.mcfunction index 79c8eb2..fb98f48 100644 --- a/easy_gui/template/tile_dropped_item/dropped_item.mcfunction +++ b/easy_gui/template/tile_dropped_item/dropped_item.mcfunction @@ -1 +1 @@ -summon item ~ ~ ~ {Tags:[egno],CustomNameVisible:1b,CustomName:'{"text":"","italic":false}',Motion:[0.0,0.3,0.0],Item:{Count:1b,id:"",tag:{display:{Name:'{"text":"","italic":false}'},eg:{is:1b,type:tile,name:}}}} \ No newline at end of file +summon item ~ ~ ~ {Tags:[egno],CustomNameVisible:1b,CustomName:'',Motion:[0.0,0.3,0.0],Item:{Count:1b,id:"",tag:{eg:{is:1b,type:tile,name:}}}} \ No newline at end of file diff --git a/easy_gui/template/tile_dropped_item/try_spawn/load.mcfunction b/easy_gui/template/tile_dropped_item/try_spawn/load.mcfunction deleted file mode 100644 index deb7aaf..0000000 --- a/easy_gui/template/tile_dropped_item/try_spawn/load.mcfunction +++ /dev/null @@ -1,5 +0,0 @@ -setblock ~ ~ ~ [facing=up]{CustomName:'{"text":"","italic":false}'} destroy -summon item_frame ~ ~ ~ {Tags:[eg.,egset],Facing:1b,Item:{id:"",Count:1b,tag:{display:{Name:'{"text":"","italic":false}'},HideFlags:1}},Invulnerable:1b,Fixed:1b,Invisible:1b} - -kill @s -execute positioned ~ ~ ~ run tag @e[sort=nearest,limit=1,type=item_frame,tag=egset] remove egset diff --git a/example/backpack.yaml b/example/backpack.yaml new file mode 100644 index 0000000..8d818ba --- /dev/null +++ b/example/backpack.yaml @@ -0,0 +1,34 @@ +id: backpack +type: drop +block: minecraft:barrel +item: + id: minecraft:leather_chestplate + tag: + display: + Name: {text: Backpack, italic: false} + Unbreakable: true + HideFlags: 127 + AttributeModifiers: [] + CustomModelData: 54621503 + +load: 'say load' +destroy: 'say destroy' +tick: 'say tick' + +slot: + 0..8,18..25: + type: label + item: + id: minecraft:black_stained_glass_pane + 26: + type: label + item: + id: barrier + tag: + display: + Name: {text: Close, color: red, italic: false} + click: 'say click' + 9..17: + type: drop + cond: if + data: 'eg' \ No newline at end of file diff --git a/example/scribing_table.yaml b/example/scribing_table.yaml new file mode 100644 index 0000000..d295833 --- /dev/null +++ b/example/scribing_table.yaml @@ -0,0 +1,35 @@ +id: st +type: spawn_egg +block: minecraft:barrel +item: + id: minecraft:cow_spawn_egg + tag: + display: + Name: {text: Scribing Table, italic: false, color: dark_purple} + CustomModelData: 54621501 + +load: 'say load' +destroy: 'say destroy' +tick: 'say tick' + +slot: + 0..9,11,13,15,17..26: + type: label + item: + id: minecraft:black_stained_glass_pane + 10: + type: n_left + n: 1 + 12,16: + type: drop + cond: never + 14: + type: label + item: + id: minecraft:feather + tag: + display: + Name: {text: Scribe !, italic: false, color: yellow} + CustomModelData: 54621501 + click: 'function #cc:scribe' + \ No newline at end of file diff --git a/example/working_table.yaml b/example/working_table.yaml new file mode 100644 index 0000000..91ea6b5 --- /dev/null +++ b/example/working_table.yaml @@ -0,0 +1,30 @@ +id: wt +type: spawn_egg +block: minecraft:barrel +item: + id: minecraft:cow_spawn_egg + tag: + display: + Name: {text: Working Table, italic: false, color: dark_purple} + CustomModelData: 54621502 + +load: 'say load' +destroy: 'say destroy' +tick: 'say tick' + +slot: + 3..8,12,14..15,17,21..26: + type: label + item: + id: minecraft:black_stained_glass_pane + 13: + type: label + item: + id: minecraft:knowledge_book + tag: + display: + Name: {text: Craft !,color: light_purple} + click: 'function #cc:craft' + 0..2,9..11,18..20,16: + type: drop + cond: never \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0204e99 Binary files /dev/null and b/requirements.txt differ diff --git a/scribing_table.yaml b/scribing_table.yaml deleted file mode 100644 index 2f8b0f9..0000000 --- a/scribing_table.yaml +++ /dev/null @@ -1,41 +0,0 @@ -id: st - -spawn_egg: - id: minecraft:cow - text: Scribing Table - enchant: false - color: dark_purple - tag: {CustomModelData: 54621501} - -setblock: destroy - -entity: - block: - id: minecraft:barrel - text: Scribing Table - color: dark_purple - item: - id: minecraft:cow_spawn_egg - tag: {CustomModelData: 54621501} - - -slot: - 0..9,11,13,15,17..26: - type: label - item: - id: minecraft:black_stained_glass_pane - 10: - type: n_left - n: 1 - 12,16: - type: drop - cond: never - 14: - type: label - item: - id: minecraft:feather - enchant: true - text: Scribe ! - color: yellow - click: 'function #cc:scribe' - \ No newline at end of file diff --git a/spawn_egg.yaml b/spawn_egg.yaml deleted file mode 100644 index 68c37b2..0000000 --- a/spawn_egg.yaml +++ /dev/null @@ -1,38 +0,0 @@ -id: example - -spawn_egg: - id: slime - text: Example GUI - enchant: true - color: dark_purple - -tick: say tick - -entity: - block: - id: dispenser - text: Example GUI - enchant: true - color: dark_purple - item: - id: writable_book - text: Example GUI - enchant: true - color: dark_purple - -slot: - 0..2,6..8: - type: label - item: - id: black_stained_glass_pane - 3,5: - type: n_left - n: 1 - 4: - type: label - item: - id: feather - enchant: true - text: Scribe ! - color: yellow - click: 'function #scribing_table:scribe' \ No newline at end of file diff --git a/tutorial.md b/tutorial.md new file mode 100644 index 0000000..dea4242 --- /dev/null +++ b/tutorial.md @@ -0,0 +1,98 @@ +# Tutorial +This part, we look into the code. Take [backpack.yaml](/example/backpack.yaml) for example. +## Apperence +```yaml +id: backpack +type: drop +block: minecraft:barrel +item: + id: minecraft:leather_chestplate + tag: + display: + Name: {text: Backpack, italic: false} + Unbreakable: true + HideFlags: 127 + AttributeModifiers: [] + CustomModelData: 54621503 +``` +* `id` is for tikc mcfunction to recongnize what GUI block it is. +* `type` is `drop` or `spawn_egg`. `drop` means that it summon GUI item when you drop the block on the ground; `spawn_egg` means the item is a spawn_egg. +* `item` is the item of the GUI block, it's in Minecraft item NBT format. The item also show at the buttom of the GUI block when it turn into the GUI block. You can make texture of it by adding `CustomModelData` tag. +## Events +```yaml +load: 'say load' +destroy: 'say destroy' +tick: 'say tick' +``` +* `load` is run when the GUI block is spawn and the item (or area cloud effect if the type is `spawn_egg`) haven't be killed, it run by the item. The GUI block have a block (barrel in this example) and an entity (always item_frame). The entity have a tag called `egset`, you can use it to do the data load, for example, you can copy the display name of the item to the custom name of the entity by `/data` command. + ```yaml + load: 'data modify entity @e[tag=egset,limit=1] CustomName set from entity @s Item.tag.display.Name' + ``` + If you want load the data of the block use `block ~ ~ ~` to locate the target. + ```yaml + load: 'data modify block ~ ~ ~ CustomName set from entity @s Item.tag.display.Name' + ``` +* `destroy` is run when the item_frame is summon and the GUI block is haven't be killed. The drop also have a tag `egset`, you can use `entity @e[tag=egset,type=ite,sort=nearest,limit=1]` to locate it. You can use `block ~ ~ ~` to locate the block. +* `tick` is run by the item_frame every tick. +## Slot Behavior +```yaml +slot: + 0..8,18..25: + type: label + item: + id: minecraft:black_stained_glass_pane + 26: + type: label + item: + id: barrier + tag: + display: + Name: {text: Close, color: red, italic: false} + click: 'say click' + 9..17: + type: drop + cond: if + data: 'eg' +``` +`slot` let you design the behavor of each slot. The key `0..8,18..25` means the slot 0~8 and 18~25 have the same behavior. +The behavor have 3 type, `drop`, `label`, `n_left` +### drop +Drop behavior have 4 condition, `always`, `never`, `if`, `unless`. +* `always` means it always drop the item in that slot. +* `never` means it never drop, you can see it as do nothing. +* `if` means if it meet the specific condition, it drops, for example + ```yaml + 9..17: + type: drop + cond: if + data: 'display' + ``` + The item drop if it has `display` tag, it may be the dyed item, renamed item ... + ```yaml + 9..17: + type: drop + cond: if + tag: {CustomModelData: 54621503} + ``` + The item drop if its `CustomModelData` value is 54621503. +* `unless` means unless it meet the specific condition, it drops. +### label +It will show a label in the slot. +```yaml +type: label +item: + id: barrier + tag: + display: + Name: {text: Close, color: red, italic: false} +click: 'say close' +``` +`item` is in NBT Format. `click` is a function, it runs by the item_frame when the label is clicked. +### n_left +```yaml +10: + type: n_left + n: 1 +``` +The item count in the slot can't exceed `n`, or it will drop the extra item. + diff --git a/working_table.yaml b/working_table.yaml deleted file mode 100644 index 598cc1c..0000000 --- a/working_table.yaml +++ /dev/null @@ -1,35 +0,0 @@ -id: wt - -spawn_egg: - id: minecraft:cow - text: Working Table - enchant: false - color: dark_green - tag: {CustomModelData: 54621502} - -entity: - block: - id: minecraft:barrel - text: Working Table - color: dark_green - item: - id: minecraft:cow_spawn_egg - tag: {CustomModelData: 54621502} - -setblock: destroy - -slot: - 3..8,12,14..15,17,21..26: - type: label - item: - id: minecraft:black_stained_glass_pane - 13: - type: label - item: - id: minecraft:knowledge_book - text: Craft ! - color: light_purple - click: 'function #cc:craft' - 0..2,9..11,18..20,16: - type: drop - cond: never \ No newline at end of file