1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-09-03 10:57:55 +00:00

Nuke treasure disks

They're datapacks now. Right???
This commit is contained in:
Jonathan Coates
2021-06-09 09:19:21 +01:00
parent e8d90b94ec
commit 2279f5044d
180 changed files with 353 additions and 12220 deletions

View File

@@ -1,10 +0,0 @@
{
"type": "computercraft:impostor_shapeless",
"group": "computercraft:disk",
"ingredients": [
{ "item": "minecraft:redstone" },
{ "item": "minecraft:paper" },
{ "item": "${dye}" }
],
"result": { "item": "computercraft:disk", "nbt": { "color": ${colour} } }
}

View File

@@ -1,120 +0,0 @@
--- Rewrites language files in order to be consistent with en_us.
--
-- This will take every given language file and rewrite it to be in the same
-- order as the en_us file. Any keys which appear in the given file, but not
-- in en_us are warned about.
--
-- When passing the `-v` flag, we also print any missing commands.
--
-- Note, this is not intended to be a fool-proof tool, rather a quick way to
-- ensure language files are mostly correct.
--
-- @example
--
-- # Reformat all files
-- > lua tools/language.lua
-- # Reformat German, and warn about missing entries
-- > lua tools/language.lua -v de_de
local primary = "en_us"
local secondary = {
"de_de",
"es_es",
"fr_fr",
"it_it",
"pt_br",
"sv_se",
"zh_cn",
}
local verbose = false
local path = "src/main/resources/assets/computercraft/lang/%s.json"
local args = { ... }
for i = #args, 1, -1 do
if args[i] == "-v" or args[i] == "--verbose" then
table.remove(args, i)
verbose = true
end
end
if #args > 0 then
secondary = args
end
-- Read the contents of the primary language file
local primary_contents, n = {}, 1
for line in io.lines(path:format(primary)) do
local key = line:match('^%s*"([^"]+)":.*$')
if key then
primary_contents[n], n = key, n + 1
elseif line == "" or line == "{" or line == "}" then
primary_contents[n], n = line, n + 1
else
io.stderr:write(("Unknown line %q in %s\n"):format(line, primary))
os.exit(1)
end
end
for _, language in ipairs(secondary) do
local keys = {}
for line in io.lines(path:format(language)) do
local key, value = line:match('^%s*"([^"]+)":%s*(.-),?$')
if key then
if keys[key] then
io.stderr:write(("Duplicate keys for %q in %q\n"):format(key, language))
os.exit(10)
end
keys[key] = value
elseif line ~= "" and line ~= "{" and line ~= "}" then
io.stderr:write(("Unknown line %q in %s\n"):format(line, language))
os.exit(1)
end
end
local h = io.open(path:format(language), "wb")
h:write("{")
local has_blank, has_any = false, false
for _, line in ipairs(primary_contents) do
if line == "{" or line == "}" then
-- Skip
elseif line == "" then
has_blank = true
else
local translated = keys[line]
if translated then
if has_any then h:write(",") else has_any = true end
if has_blank then h:write("\n") has_blank = false end
h:write(("\n %q: %s"):format(line, translated))
keys[line] = nil
elseif verbose then
io.stderr:write(("Missing translation %q for %q\n"):format(line, language))
end
end
end
if next(keys) ~= nil then
local extra = {}
for k, v in pairs(keys) do
extra[#extra + 1] = ("\n %q: %s"):format(k, v)
end
table.sort(extra)
io.stderr:write(("%d additional unknown translation keys in %q\n"):format(#extra, language))
has_blank = true
for _, line in ipairs(extra) do
if has_any then h:write(",") else has_any = true end
if has_blank then h:write("\n") has_blank = false end
h:write(line)
end
end
h:write("\n}\n")
h:close()
end

43
tools/language.py Executable file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python3
"""
Rewrites language files in order to be consistent with en_us.
This will take every given language file and rewrite it to be in the same
order as the en_us file. Any keys which appear in the given file, but not
in en_us are removed.
Note, this is not intended to be a fool-proof tool, rather a quick way to
ensure language files are mostly correct.
"""
import pathlib, sys, json
from collections import OrderedDict
root = pathlib.Path("src/main/resources/assets/computercraft/lang")
with (root / "en_us.json").open(encoding="utf-8") as file:
en_us = json.load(file, object_hook=OrderedDict)
for path in root.glob("*.json"):
if path.name == "en_us.json":
continue
with path.open(encoding="utf-8") as file:
lang = json.load(file)
out = OrderedDict()
missing = 0
for k in en_us.keys():
if k not in lang:
missing += 1
elif lang[k] == "":
print("{} has empty translation for {}".format(path.name, k))
else:
out[k] = lang[k]
with path.open("w", encoding="utf-8", newline="\n") as file:
json.dump(out, file, indent=4, ensure_ascii=False)
file.write("\n")
if missing > 0:
print("{} has {} missing translations.".format(path.name, missing))

114
tools/parse-reports.py Executable file
View File

@@ -0,0 +1,114 @@
#!/usr/bin/env python3
"""
Parse reports generated by Gradle and convert them into GitHub annotations.
See https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md and
https://github.com/actions/toolkit/blob/master/docs/commands.md.
"""
from typing import Optional, Tuple
import pathlib
import xml.etree.ElementTree as ET
import re
import os.path
LUA_ERROR_LOCATION = re.compile(r"^\s+(/[\w./-]+):(\d+):", re.MULTILINE)
JAVA_ERROR_LOCATION = re.compile(r"^\tat ([\w.]+)\.[\w]+\([\w.]+:(\d+)\)$", re.MULTILINE)
ERROR_MESSAGE = re.compile(r"(.*)\nstack traceback:", re.DOTALL)
SPACES = re.compile(r"\s+")
SOURCE_LOCATIONS = [
"src/main/java",
"src/main/resources/data/computercraft/lua",
"src/test/java",
"src/test/resources",
]
def find_file(path: str) -> Optional[str]:
while len(path) > 0 and path[0] == '/':
path = path[1:]
for source_dir in SOURCE_LOCATIONS:
child_path = os.path.join(source_dir, path)
if os.path.exists(child_path):
return child_path
return None
def find_location(message: str) -> Optional[Tuple[str, str]]:
location = LUA_ERROR_LOCATION.search(message)
if location:
file = find_file(location[1])
if file:
return file, location[2]
for location in JAVA_ERROR_LOCATION.findall(message):
file = find_file(location[0].replace(".", "/") + ".java")
if file:
return file, location[1]
return None
def parse_junit() -> None:
"""
Scrape JUnit test reports for errors. We determine the location from the Lua
or Java stacktrace.
"""
print("::add-matcher::.github/matchers/junit.json")
for path in pathlib.Path("build/test-results/test").glob("TEST-*.xml"):
for testcase in ET.parse(path).getroot():
if testcase.tag != "testcase":
continue
for result in testcase:
if result.tag != "failure":
continue
name = f'{testcase.attrib["classname"]}.{testcase.attrib["name"]}'
message = result.attrib.get('message')
location = find_location(result.text)
error = ERROR_MESSAGE.match(message)
if error:
error = error[1]
else:
error = message
if location:
print(f'## {location[0]}:{location[1]}: {name} failed: {SPACES.sub(" ", error)}')
else:
print(f'::error::{name} failed')
print("::group::Full error message")
print(result.text)
print("::endgroup")
print("::remove-matcher owner=junit::")
def parse_checkstyle() -> None:
"""
Scrape JUnit test reports for errors. We determine the location from the Lua
or Java stacktrace.
"""
print("::add-matcher::.github/matchers/checkstyle.json")
for path in pathlib.Path("build/reports/checkstyle/").glob("*.xml"):
for file in ET.parse(path).getroot():
for error in file:
filename = os.path.relpath(file.attrib['name'])
attrib = error.attrib
print(f'{attrib["severity"]} {filename}:{attrib["line"]}:{attrib.get("column", 1)}: {SPACES.sub(" ", attrib["message"])}')
print("::remove-matcher owner=checkstyle::")
if __name__ == '__main__':
parse_junit()
parse_checkstyle()

View File

@@ -1,22 +0,0 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [ "computercraft:${path}" ]
},
"criteria": {
"has_items": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{ "item": "computercraft:pocket_computer_${pocket_family}" },
{ "item": "${upgrade_item}" }
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": { "recipe": "computercraft:${path}" }
}
},
"requirements": [ [ "has_items", "has_the_recipe" ] ]
}

View File

@@ -1,13 +0,0 @@
{
"type": "computercraft:impostor_shaped",
"group": "computercraft:upgrade_pocket_${pocket_family}",
"pattern": [
"#",
"T"
],
"key": {
"#": { "item": "${upgrade_item}" },
"T": { "item": "computercraft:pocket_computer_${pocket_family}" }
},
"result": { "item": "computercraft:pocket_computer_${pocket_family}", "nbt": { "Upgrade": "${upgrade_id}" } }
}

View File

@@ -1,136 +0,0 @@
--- Generates impostor recipes and advancements for several dynamic recipes.
--
-- Namely:
-- - Turtle upgrades
-- - Pocket upgrades
-- - Disk (each colour)
--
-- Note, this is largely intended for the recipe book, as that requires a fixed
-- set of recipes.
--- All turtle upgrades, and an optional item for this upgrade.
local turtle_upgrades = {
{ "computercraft:wireless_modem_normal" },
{ "computercraft:wireless_modem_advanced" },
{ "computercraft:speaker" },
{ "minecraft:crafting_table" },
{ "minecraft:diamond_sword" },
{ "minecraft:diamond_shovel" },
{ "minecraft:diamond_pickaxe" },
{ "minecraft:diamond_axe" },
{ "minecraft:diamond_hoe" },
}
--- All pocket upgrades, and an optional item for this upgrade.
local pocket_upgrades = {
{ "computercraft:wireless_modem_normal" },
{ "computercraft:wireless_modem_advanced" },
{ "computercraft:speaker" },
}
--- All dye/disk colours
local colours = {
{ 0x111111, "minecraft:black_dye" },
{ 0xcc4c4c, "minecraft:red_dye" },
{ 0x57A64E, "minecraft:green_dye" },
{ 0x7f664c, "minecraft:brown_dye" },
{ 0x3366cc, "minecraft:blue_dye" },
{ 0xb266e5, "minecraft:purple_dye" },
{ 0x4c99b2, "minecraft:cyan_dye" },
{ 0x999999, "minecraft:light_gray_dye" },
{ 0x4c4c4c, "minecraft:gray_dye" },
{ 0xf2b2cc, "minecraft:pink_dye" },
{ 0x7fcc19, "minecraft:lime_dye" },
{ 0xdede6c, "minecraft:yellow_dye" },
{ 0x99b2f2, "minecraft:light_blue_dye" },
{ 0xe57fd8, "minecraft:magenta_dye" },
{ 0xf2b233, "minecraft:orange_dye" },
{ 0xf0f0f0, "minecraft:white_dye" },
}
--- Read the provided file into a string, exiting the program if not found.
--
-- @tparam string file The file to read
-- @treturn string The file's contents
local function read_all(file)
local h, e = io.open(file, "rb")
if not h then
io.stderr:write("Cannot open " .. file .. ": " .. tostring(e))
os.exit(1)
end
local c = h:read "*a"
h:close()
return c
end
--- Write the provided string into a file, exiting on failure.
--
-- @tparam string file The file to read
-- @tparam string contents The new contents
local function write_all(file, contents)
local h, e = io.open(file, "wb")
if not h then
io.stderr:write("Cannot open " .. file .. ": " .. tostring(e))
os.exit(1)
end
h:write(contents)
h:close()
end
--- Format template strings of the form `${key}` using the given substituion
-- table.
local function template(str, subs)
return str:gsub("%$%{([^}]+)%}", function(k)
return subs[k] or error("Unknown key " .. k)
end)
end
-- Write turtle upgrades
local turtle_recipe = read_all "tools/turtle_upgrade_recipe.json"
local turtle_advance = read_all "tools/turtle_upgrade_advancement.json"
for _, turtle_family in ipairs { "normal", "advanced" } do
for _, upgrade in ipairs(turtle_upgrades) do
local upgrade_id, upgrade_item = upgrade[1], upgrade[2] or upgrade[1]
local path = ("generated/turtle_%s/%s"):format(turtle_family, (upgrade_id:gsub(":", "_")))
local keys = {
upgrade_id = upgrade_id, upgrade_item = upgrade_item,
turtle_family = turtle_family,
path = path,
}
write_all("src/main/resources/data/computercraft/recipes/" .. path .. ".json", template(turtle_recipe, keys))
write_all("src/main/resources/data/computercraft/advancements/recipes/" .. path .. ".json", template(turtle_advance, keys))
end
end
-- Write pocket upgrades
local pocket_recipe = read_all "tools/pocket_upgrade_recipe.json"
local pocket_advance = read_all "tools/pocket_upgrade_advancement.json"
for _, pocket_family in ipairs { "normal", "advanced" } do
for _, upgrade in ipairs(pocket_upgrades) do
local upgrade_id, upgrade_item = upgrade[1], upgrade[2] or upgrade[1]
local path = ("generated/pocket_%s/%s"):format(pocket_family, (upgrade_id:gsub(":", "_")))
local keys = {
upgrade_id = upgrade_id, upgrade_item = upgrade_item,
pocket_family = pocket_family,
path = path,
}
write_all("src/main/resources/data/computercraft/recipes/" .. path .. ".json", template(pocket_recipe, keys))
write_all("src/main/resources/data/computercraft/advancements/recipes/" .. path .. ".json", template(pocket_advance, keys))
end
end
-- Write disk recipe
local disk_recipe = read_all "tools/disk_recipe.json"
for i, colour in ipairs(colours) do
local path = ("generated/disk/disk_%s"):format(i)
local keys = {
dye = colour[2], colour = colour[1],
path = path,
}
write_all("src/main/resources/data/computercraft/recipes/" .. path .. ".json", template(disk_recipe, keys))
end

View File

@@ -1,22 +0,0 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [ "computercraft:${path}" ]
},
"criteria": {
"has_items": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{ "item": "computercraft:turtle_${turtle_family}" },
{ "item": "${upgrade_item}" }
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": { "recipe": "computercraft:${path}" }
}
},
"requirements": [ [ "has_items", "has_the_recipe" ] ]
}

View File

@@ -1,12 +0,0 @@
{
"type": "computercraft:impostor_shaped",
"group": "computercraft:upgrade_turtle_${turtle_family}",
"pattern": [
"#T"
],
"key": {
"#": { "item": "${upgrade_item}" },
"T": { "item": "computercraft:turtle_${turtle_family}" }
},
"result": { "item": "computercraft:turtle_${turtle_family}", "nbt": { "RightUpgrade": "${upgrade_id}" } }
}