Skip to content

Commit

Permalink
Be more explicit about when pack overlays apply
Browse files Browse the repository at this point in the history
This makes sure per file and pack version there is always a unique overlay.
Previously, when multiple overrides existed for a single file, only the minimum
was specified, giving ambigious overrides to Minecraft with unknown / untested
behavior
  • Loading branch information
NeunEinser committed Apr 26, 2024
1 parent b514449 commit 8404002
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# @context
# entity The player to check

#NEUN_SCRIPT since 33
#NEUN_SCRIPT since 33 until 39
clear @s minecraft:leather_boots[minecraft:trim={pattern:"minecraft:coast",material:"minecraft:lapis"}] 1
clear @s minecraft:leather_boots[minecraft:trim={pattern:"minecraft:dune",material:"minecraft:lapis"}] 1
clear @s minecraft:leather_boots[minecraft:trim={pattern:"minecraft:eye",material:"minecraft:lapis"}] 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# @context
# entity The player to check

#NEUN_SCRIPT since 33
#NEUN_SCRIPT since 33 until 39
execute if items entity @s container.* minecraft:leather_boots[minecraft:trim={pattern:"minecraft:coast",material:"minecraft:lapis"}] run scoreboard players set @s fetchr.has_item 1
execute if items entity @s container.* minecraft:leather_boots[minecraft:trim={pattern:"minecraft:dune",material:"minecraft:lapis"}] run scoreboard players set @s fetchr.has_item 1
execute if items entity @s container.* minecraft:leather_boots[minecraft:trim={pattern:"minecraft:eye",material:"minecraft:lapis"}] run scoreboard players set @s fetchr.has_item 1
Expand Down
6 changes: 3 additions & 3 deletions datapack/pack.mcmeta
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"entries": [
{
"formats": {"min_inclusive": 28, "max_inclusive": 2147483647},
"directory": "pack_format_28"
"directory": "pack_format_from_28"
},
{
"formats": {"min_inclusive": 33, "max_inclusive": 2147483647},
"directory": "pack_format_33"
"directory": "pack_format_from_33"
},
{
"formats": {"min_inclusive": 37, "max_inclusive": 2147483647},
"directory": "pack_format_37"
"directory": "pack_format_from_37"
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions neunscript.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "Fetchr",
"version": "5.1.2",
"version": "5.1.3",
"mc": "1.20.2",
"target": "dist",
"vars": {
"version_long_name": "5.1.2",
"version_long_name": "5.1.3",
"rp_version": "23",
"realms": false
},
Expand All @@ -28,7 +28,7 @@
"realms": {
"vars": {
"realms": true,
"version_long_name": "5.1.2 (Realms)"
"version_long_name": "5.1.3 (Realms)"
}
}
},
Expand Down
31 changes: 19 additions & 12 deletions neunscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def main():

def iterate_files(config: dict, source: str, target: str, mc_version_info: dict | None):
requested_rp_sha = []
pack_formats_for_overlay = set()
pack_formats_for_overlay = []
remove_extensions = config.get("remove_file_types")
versionDict: dict | None = config.get("versions")
if versionDict == None:
Expand Down Expand Up @@ -206,13 +206,18 @@ def iterate_files(config: dict, source: str, target: str, mc_version_info: dict
file_content = minify_json_file(file_content)
elif file_name.endswith(".mcfunction"):
function_result = minify_function_file(file_content, version_config, 1)
for pack_format in function_result.get("pack_formats"):
pack_formats_for_overlay.add(pack_format)
pack_formats = sorted(function_result.get("pack_formats"))
for i in range(0, len(pack_formats)):
pack_format = pack_formats[i]
max_format = pack_formats[i+1] - 1 if i+1 < len(pack_formats) else None
pack_formats_for_overlay.append([pack_format, max_format])
overlay_content = minify_function_file(file_content, version_config, pack_format).get("content")
overlay_path = f"{out_root}{os.sep}pack_format_{pack_format}{os.sep}{relative_path}"
os.makedirs(overlay_path, exist_ok=True)
with open(f"{overlay_path}{os.sep}{file_name}", "w", encoding="utf-8") as file:
file.write(overlay_content)

if overlay_content:
overlay_path = f"{out_root}{os.sep}pack_format_from_{pack_format}{f'_until_{max_format}' if max_format != None else ''}{os.sep}{relative_path}"
os.makedirs(overlay_path, exist_ok=True)
with open(f"{overlay_path}{os.sep}{file_name}", "w", encoding="utf-8") as file:
file.write(overlay_content)
file_content: str = function_result.get("content")
if override == None:
global lines
Expand All @@ -237,9 +242,11 @@ def iterate_files(config: dict, source: str, target: str, mc_version_info: dict
entries = []

for pack_format in pack_formats_for_overlay:
overlay_name = f"pack_format_{pack_format}"
min_inc = pack_format[0]
max_inc = pack_format[1] if pack_format[1] != None else 2**31-1
overlay_name = f"pack_format_from_{min_inc}{f'_until_{max_inc}' if max_inc != 2**31-1 else ''}"
if not any (entry["directory"] == overlay_name for entry in entries):
entries.append({"formats": {"min_inclusive": pack_format, "max_inclusive": 2**31-1 }, "directory": overlay_name })
entries.append({"formats": {"min_inclusive": min_inc, "max_inclusive": max_inc}, "directory": overlay_name })
overlays["entries"] = entries
pack_def["overlays"] = overlays
file.seek(0)
Expand Down Expand Up @@ -320,7 +327,7 @@ def minify_function_file(file_content: str, config: dict, pack_format: int):
output=""
remove=0
uncomment=0
pack_formats = []
pack_formats = set()

for line in file_content.splitlines():
line = line.strip()
Expand Down Expand Up @@ -389,12 +396,12 @@ def minify_function_file(file_content: str, config: dict, pack_format: int):
raise ValueError("until/since needs at least one argument")
min_value = 1
max_value = None
pack_formats.append(int(command[1]))
pack_formats.add(int(command[1]))
if command[0] == "since":
min_value = int(command[1])
if len(command) >= 4 and command[2] == "until":
max_value = int(command[3])
pack_formats.append(max_value)
pack_formats.add(max_value)
else:
max_value = int(command[1])
if pack_format >= min_value and (max_value is None or pack_format < max_value):
Expand Down

0 comments on commit 8404002

Please sign in to comment.