Skip to content

Commit

Permalink
Merge pull request #150 from TeamTernate/v1.6.3
Browse files Browse the repository at this point in the history
v1.7
  • Loading branch information
bradytheinventor authored Jun 5, 2024
2 parents 413970c + ccfccf2 commit 0401b17
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# app version
MAJOR = 1
MINOR = 6
PATCH = 2
MINOR = 7
PATCH = 0

# legacy datapack version (final 1.x version)
DP_LEGACY_MAJOR = 1
Expand Down
6 changes: 5 additions & 1 deletion src/contents/datapack/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from src.contents.datapack.v2p0 import DatapackContents_v2p0
from src.contents.datapack.v2p1 import DatapackContents_v2p1
from src.contents.datapack.v2p2 import DatapackContents_v2p2
from src.contents.datapack.v2p3 import DatapackContents_v2p3

# Factory to select between different DatapackContents child
# classes. Uses pack_format to pick which datapack version to use
Expand All @@ -13,7 +15,9 @@
# with the given pack_format
versions = [
DatapackContents_v2p0,
DatapackContents_v2p1
DatapackContents_v2p1,
DatapackContents_v2p2,
DatapackContents_v2p3
]

def get(pack_format: int):
Expand Down
13 changes: 5 additions & 8 deletions src/contents/datapack/v2p0.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@


# pack.mcmeta
# pack_format must be specially encoded - datapack formatter
# will see the "(int)" prefix and cast it to an integer
# after string formatting
pack_mcmeta = {
'path': ['pack.mcmeta'],
'repeat': 'single',
'contents': \
{
"pack": {
"pack_format": -1,
"pack_format": '(int){pack_format}',
"description": "Adds {dp_num_discs} custom music discs"
}
}
Expand Down Expand Up @@ -510,6 +513,7 @@ def add_contents(self):
self.jukebox_tick_timers = jukebox_tick_timers
self.on_placed_disc = on_placed_disc
self.on_placed_jukebox = on_placed_jukebox
self.pack_mcmeta = pack_mcmeta
self.play = play
self.play_duration = play_duration
self.pre_play = pre_play
Expand All @@ -533,13 +537,6 @@ def add_contents(self):
def version_str(self):
return f"v{self.version_major}.{self.version_minor}"

#pack.mcmeta
def get_pack_mcmeta(self, pack_format: int):
#reach inside and set pack_format manually since there's no
# string formatting equivalent for integers
pack_mcmeta['contents']['pack']['pack_format'] = pack_format
return pack_mcmeta

#creeper.json
def get_creeper_music_entry_base(self):
return creeper_music_entry_base
Expand Down
93 changes: 93 additions & 0 deletions src/contents/datapack/v2p2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
#
#Infinite Music Discs datapack v2.2 contents
#Generation tool, datapack design, and resourcepack design by link2_thepast

from src.contents.datapack.v2p1 import DatapackContents_v2p1



# function tags
tick = {
'path': ['data', 'minecraft', 'tags', 'functions', 'tick.json'],
'repeat': 'single',
'contents': \
{
"values": [
"{datapack_name}:watchdog_setup_load_tick",
"{datapack_name}:register_players_tick",
"{datapack_name}:jukebox_event_tick"
]
}
}

# top-level functions

help = {
'path': ['data', '{datapack_name}', 'functions', 'help.mcfunction'],
'repeat': 'single',
'contents': \
"""
tellraw @s {{"text":"\\nInfinite Music Discs Help", "color":"yellow", "bold":true}}
tellraw @s [{{"text":"\\n[", "color":"gold"}}, {{"text":"?", "color":"green", "bold":true}}, {{"text":"] A datapack & resourcepack that work together to add new music discs to Minecraft. Use ", "color":"gold"}}, {{"text":"the desktop app", "clickEvent":{{"action":"open_url", "value":"https://github.com/TeamTernate/infinite-music-discs"}}, "color":"aqua", "underlined":true}}, {{"text":" to generate your own packs and add your own music. Follow the project on ", "color":"gold"}}, {{"text":"CurseForge", "clickEvent":{{"action":"open_url", "value":"https://www.curseforge.com/minecraft/customization/infinite-music-discs"}}, "color":"aqua", "underlined":true}}, {{"text":" for update notifications!", "color":"gold"}}]
tellraw @s [{{"text":"\\n[", "color":"gold"}}, {{"text":"!", "color":"red", "bold":true}}, {{"text":"]", "color":"gold"}}, {{"text":" Install both the datapack and resourcepack or Infinite Music Discs will not work! The datapack goes in your world's datapack folder, and the resourcepack goes in your resourcepacks folder.", "color":"red"}}]
tellraw @s [{{"text":"\\n[", "color":"gold"}}, {{"text":"i", "color":"aqua", "bold":true}}, {{"text":"] To obtain custom discs in survival, get a skeleton to kill a creeper. The creeper will drop a music disc, and there's a chance it will be one of your custom music discs. All discs (including the vanilla discs) have an equal chance to drop. The more discs your pack adds, the harder it will be to get any particular disc. You might consider building a music disc farm.", "color":"gold"}}]
tellraw @s [{{"text":"\\n[", "color":"gold"}}, {{"text":"i", "color":"aqua", "bold":true}}, {{"text":"] Give yourself discs in creative with these commands:", "color":"gold"}}]
tellraw @s [{{"text":" - ", "color":"gold"}}, {{"text":"/function {datapack_name}:give_all_discs", "color":"yellow"}}]
tellraw @s [{{"text":" - ", "color":"gold"}}, {{"text":"/function {datapack_name}:give_<disc name>", "color":"yellow"}}]
tellraw @s [{{"text":"\\n[", "color":"gold"}}, {{"text":"i", "color":"aqua", "bold":true}}, {{"text":"] Hoppers and droppers can add/remove custom music discs from jukeboxes!", "color":"gold"}}]
tellraw @s [{{"text":"\\n[", "color":"gold"}}, {{"text":"i", "color":"aqua", "bold":true}}, {{"text":"] Custom tracks not playing? If you hear the 11 disc playing instead of your custom disc, try breaking and replacing the jukebox.", "color":"gold"}}]
tellraw @s [{{"text":"\\n[", "color":"gold"}}, {{"text":"i", "color":"aqua", "bold":true}}, {{"text":"] Is your music playing 'inside your head' instead of from the jukebox? Try checking the \\"{mix_mono_title}\\" setting when you generate your pack. Most music is stereo, and Minecraft plays stereo sounds globally instead of attaching them to a spot in the world.", "color":"gold"}}]
tellraw @s [{{"text":"\\n[", "color":"gold"}}, {{"text":"i", "color":"aqua", "bold":true}}, {{"text":"] Still having problems? Use ", "color":"gold"}}, {{"text":"the issue tracker", "clickEvent":{{"action":"open_url", "value":"https://github.com/TeamTernate/infinite-music-discs/issues"}}, "color":"aqua", "underlined":true}}, {{"text":" to report bugs or ask for help.", "color":"gold"}}]
"""
}

setup_load = {
'path': ['data', '{datapack_name}', 'functions', 'setup_load.mcfunction'],
'repeat': 'single',
'contents': \
"""
scoreboard objectives add imd_player_id dummy
scoreboard objectives add imd_disc_id dummy
scoreboard objectives add imd_rc_steps dummy
scoreboard objectives add imd_play_time dummy
scoreboard objectives add imd_stop_11_time dummy
scoreboard objectives add imd_is_loaded dummy
scoreboard players set #imd_is_loaded imd_is_loaded 1
advancement revoke @a only {datapack_name}:placed_disc
advancement revoke @a only {datapack_name}:placed_jukebox
tellraw @a [{{"text":"Infinite Music Discs {dp_version_str} by link2_thepast", "color":"gold"}}]
tellraw @a [{{"text":"Type ", "color":"gold"}}, {{"text":"/function {datapack_name}:help", "color":"yellow"}}, {{"text":" for help", "color":"gold"}}]
"""
}

watchdog_setup_load_tick = {
'path': ['data', '{datapack_name}', 'functions', 'watchdog_setup_load_tick.mcfunction'],
'repeat': 'single',
'contents': \
"""
scoreboard objectives add imd_is_loaded dummy
execute unless score #imd_is_loaded imd_is_loaded matches 1 run function {datapack_name}:setup_load
"""
}



# See src.contents.datapack.v2p0 for info on this class structure
class DatapackContents_v2p2(DatapackContents_v2p1):

min_pack_format = 26
version_major = 2
version_minor = 2

def add_contents(self):
super().add_contents()

self.tick = tick
self.help = help
self.setup_load = setup_load
self.watchdog_setup_load_tick = watchdog_setup_load_tick


96 changes: 96 additions & 0 deletions src/contents/datapack/v2p3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
#
#Infinite Music Discs datapack v2.3 contents
#Generation tool, datapack design, and resourcepack design by link2_thepast

from src.contents.datapack.v2p2 import DatapackContents_v2p2



# creeper loot table
# custom_model_data must be specially encoded - datapack formatter
# will see the "(int)" prefix and cast it to an integer
# after string formatting
creeper_music_entry_custom = {
'type':'minecraft:item',
'weight':1,
'name':'minecraft:music_disc_11',
'functions':[{
'function':'minecraft:set_components',
'components':{
'minecraft:custom_model_data':'(int){entry.custom_model_data}',
'minecraft:hide_additional_tooltip':{},
'minecraft:lore':[
'{{\"text\":\"{entry.title}\", \"color\":\"gray\", \"italic\":false}}'
]
}
}]
}



# top-level functions
give_disc = {
'path': ['data', '{datapack_name}', 'functions', 'give_{entry.internal_name}.mcfunction'],
'repeat': 'copy',
'contents': \
"""
execute at @s run summon item ~ ~ ~ {{Item:{{id:"minecraft:music_disc_11", Count:1b, components:{{custom_model_data:{entry.custom_model_data}, hide_additional_tooltip:{{}}, lore:["{{\\"text\\":\\"{entry.title}\\", \\"color\\":\\"gray\\", \\"italic\\":false}}"]}}}}}}
"""
}

jukebox_on_play = {
'path': ['data', '{datapack_name}', 'functions', 'jukebox_on_play.mcfunction'],
'repeat': 'single',
'contents': \
"""
tag @s add imd_is_playing
execute if data block ~ ~ ~ RecordItem.components.minecraft:custom_model_data run tag @s add imd_has_custom_disc
execute as @s[tag=imd_has_custom_disc] run function {datapack_name}:pre_play
"""
}

pre_play = {
'path': ['data', '{datapack_name}', 'functions', 'pre_play.mcfunction'],
'repeat': 'single',
'contents': \
"""
execute store result score @s imd_disc_id run data get block ~ ~ ~ RecordItem.components.minecraft:custom_model_data
function {datapack_name}:play_duration
scoreboard players set @s imd_stop_11_time 3
function {datapack_name}:watchdog_reset_tickcount
execute as @a[distance=..64] run function {datapack_name}:register_jukebox_listener
"""
}

set_disc_track = {
'path': ['data', '{datapack_name}', 'functions', 'set_disc_track.mcfunction'],
'repeat': 'copy_within',
'contents': \
"""
execute as @s if items entity @s weapon.mainhand minecraft:music_disc_11[custom_model_data={entry.custom_model_data}] run item replace entity @s weapon.mainhand with minecraft:music_disc_11[custom_model_data={entry.custom_model_data},hide_additional_tooltip={{}},lore=["{{\\"text\\":\\"{entry.title}\\", \\"color\\":\\"gray\\", \\"italic\\":false}}"]]
"""
}



# See src.contents.datapack.v2p0 for info on this class structure
class DatapackContents_v2p3(DatapackContents_v2p2):

min_pack_format = 41
version_major = 2
version_minor = 3

def add_contents(self):
super().add_contents()

self.give_disc = give_disc
self.jukebox_on_play = jukebox_on_play
self.pre_play = pre_play
self.set_disc_track = set_disc_track

#creeper.json
def get_creeper_music_entry_custom(self):
return creeper_music_entry_custom


1 change: 1 addition & 0 deletions src/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class DisplayStrings():

#dictionary to associate game version : pack format version
PackFormatsDict = {
'1.20.5 - 1.20.6': {'dp':41, 'rp':32},
'1.20.3 - 1.20.4': {'dp':26, 'rp':22},
'1.20.2': {'dp':18, 'rp':18},
'1.20 - 1.20.1': {'dp':15, 'rp':15},
Expand Down
4 changes: 3 additions & 1 deletion src/generator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tempfile
import multiprocessing

from math import ceil
from typing import Callable

from contextlib import contextmanager
Expand Down Expand Up @@ -234,7 +235,8 @@ def get_track_length(self, track_entry: DiscListEntryContents):
length_s = meta_ogg.info.length

#convert from seconds to Minecraft ticks (20 t/s)
length_t = int(length_s) * 20
#round up to avoid track getting cut off at the end
length_t = int(ceil(length_s * 20.0))

except FileNotFoundError:
raise IMDException(Status.BAD_OGG_CONVERT)
Expand Down
21 changes: 15 additions & 6 deletions src/generator/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ def generate_datapack(self, entry_list: DiscListContents, user_settings={}):
os.makedirs(datapack_name)

with self.set_directory(datapack_name):
#write 'pack.mcmeta'
#reach into dict and set pack_format manually, since there's no str.format()
# equivalent for integers
self.write_single(dp.get_pack_mcmeta(pack_format), locals())

#write 'creeper.json'
#generate JSON for music disc entries, then reach into dict and add them
# to the drop pool manually
Expand Down Expand Up @@ -279,6 +274,11 @@ def zip_pack(self, pack_name: str):
# use ** to expand fmt_dict into kwargs for formatting
def fmt_str(self, str: str, fmt_dict):
return str.format(**fmt_dict)

# apply string formatting, but cast the result to int
# useful for pack_format, setting minecraft:custom_model_data, etc.
def fmt_int(self, int_str: str, fmt_dict):
return int(self.fmt_str(int_str, fmt_dict))

# recursively apply string formatting to any string-type
# value in the given json dict or json sub-list
Expand All @@ -297,9 +297,18 @@ def fmt_json(self, obj: Union[dict, list], fmt_dict):

for k in iterator:

# object is a string - format
if type(obj[k]) == str:
fmt_obj[k] = self.fmt_str(obj[k], fmt_dict)
# integer encoded as formatted string
if '(int){' in obj[k]:
int_obj = obj[k].replace('(int){', '{')
fmt_obj[k] = self.fmt_int(int_obj, fmt_dict)

# true string
else:
fmt_obj[k] = self.fmt_str(obj[k], fmt_dict)

# object is a list or dict - continue recursing
elif type(obj[k]) in [dict, list]:
fmt_obj[k] = self.fmt_json(obj[k], fmt_dict)

Expand Down

0 comments on commit 0401b17

Please sign in to comment.