Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- lib/lunajson/src/ is not in default Lua package paths
- package.path = 'lib/lunajson/src/?.lua;' .. package.path;
- ---
- -- Put in blockstates to ignore:
- local ignore = {
- ["minecraft:redstone_wire"] = {
- east = "none", -- fix property to value
- north = "none",
- south = "none",
- west = "none",
- },
- ["minecraft:redstone_ore"] = {
- lit = false -- removes whole property
- },
- -- remove complete block (new in 1.13)
- ["minecraft:conduit"] = false,
- ["minecraft:sea_pickle"] = false,
- ["minecraft:turtle_egg"] = false,
- ["minecraft:kelp"] = false,
- ["minecraft:kelp_plant"] = false,
- ["minecraft:dried_kelp_block"] = false,
- ["minecraft:seagrass"] = false,
- ["minecraft:tall_seagrass"] = false,
- ["minecraft:brain_coral"] = false,
- ["minecraft:brain_coral_block"] = false,
- ["minecraft:brain_coral_fan"] = false,
- ["minecraft:brain_coral_wall_fan"] = false,
- ["minecraft:bubble_coral"] = false,
- ["minecraft:bubble_coral_block"] = false,
- ["minecraft:bubble_coral_fan"] = false,
- ["minecraft:bubble_coral_wall_fan"] = false,
- ["minecraft:fire_coral"] = false,
- ["minecraft:fire_coral_block"] = false,
- ["minecraft:fire_coral_fan"] = false,
- ["minecraft:fire_coral_wall_fan"] = false,
- ["minecraft:horn_coral"] = false,
- ["minecraft:horn_coral_block"] = false,
- ["minecraft:horn_coral_fan"] = false,
- ["minecraft:horn_coral_wall_fan"] = false,
- ["minecraft:tube_coral"] = false,
- ["minecraft:tube_coral_block"] = false,
- ["minecraft:tube_coral_fan"] = false,
- ["minecraft:tube_coral_wall_fan"] = false,
- ["minecraft:dead_brain_coral_block"] = false,
- ["minecraft:dead_brain_coral_fan"] = false,
- ["minecraft:dead_brain_coral_wall_fan"] = false,
- ["minecraft:dead_bubble_coral_block"] = false,
- ["minecraft:dead_bubble_coral_fan"] = false,
- ["minecraft:dead_bubble_coral_wall_fan"] = false,
- ["minecraft:dead_fire_coral_block"] = false,
- ["minecraft:dead_fire_coral_fan"] = false,
- ["minecraft:dead_fire_coral_wall_fan"] = false,
- ["minecraft:dead_horn_coral_block"] = false,
- ["minecraft:dead_horn_coral_fan"] = false,
- ["minecraft:dead_horn_coral_wall_fan"] = false,
- ["minecraft:dead_tube_coral_block"] = false,
- ["minecraft:dead_tube_coral_fan"] = false,
- ["minecraft:dead_tube_coral_wall_fan"] = false,
- ["minecraft:dark_prismarine_stairs"] = false,
- ["minecraft:prismarine_brick_stairs"] = false,
- ["minecraft:prismarine_stairs"] = false,
- ["minecraft:prismarine_slab"] = false,
- ["minecraft:prismarine_brick_slab"] = false,
- ["minecraft:dark_prismarine_slab"] = false,
- ["minecraft:spruce_trapdoor"] = false,
- ["minecraft:birch_trapdoor"] = false,
- ["minecraft:jungle_trapdoor"] = false,
- ["minecraft:acacia_trapdoor"] = false,
- ["minecraft:dark_oak_trapdoor"] = false,
- ["minecraft:spruce_button"] = false,
- ["minecraft:birch_button"] = false,
- ["minecraft:jungle_button"] = false,
- ["minecraft:acacia_button"] = false,
- ["minecraft:dark_oak_button"] = false,
- ["minecraft:stripped_oak_log"] = false,
- ["minecraft:stripped_spruce_log"] = false,
- ["minecraft:stripped_birch_log"] = false,
- ["minecraft:stripped_jungle_log"] = false,
- ["minecraft:stripped_acacia_log"] = false,
- ["minecraft:stripped_dark_oak_log"] = false,
- ["minecraft:stripped_oak_wood"] = false,
- ["minecraft:stripped_spruce_wood"] = false,
- ["minecraft:stripped_birch_wood"] = false,
- ["minecraft:stripped_jungle_wood"] = false,
- ["minecraft:stripped_acacia_wood"] = false,
- ["minecraft:stripped_dark_oak_wood"] = false,
- }
- --- Prints usage instructions to stdout.
- -- If the optional `message` is passed, output is prepended by message _and_
- -- redirected to stderr.
- function usage(message)
- if message then
- io.output(io.stderr);
- io.write(message, "\n\n");
- end
- io.write(
- "Usage: lua Generator.lua INPUTFILE OUTPUTFILE\n"..
- "Converts the Minecraft blocks.json report format to an upgrade "..
- "template from 1.12 to 1.13.\n"..
- "\n"..
- "INPUTFILE and OUTPUTFILE must point to a valid path. INPUTFILE must "..
- "be readable and OUTPUTFILE must be writable. Either can be replaced "..
- "with `-` (dash character) to point to standard-input or -output.\n");
- os.exit(message and 1 or 0);
- end
- -- Test whether the script is run in a path where it can load it's libraries
- if not pcall(function() require("lunajson.decoder") end) then
- usage("Could not load required libraries, please run `Generator.lua` "..
- "within its directory and make sure to run `git submodule update`.");
- end
- -- Check/Prepare CLI arguments
- local inpath, outpath = ...;
- io.input(io.stdin);
- io.output(io.stdout);
- if select("#", ...) ~= 2 then
- usage("Incorrect number of arguments.");
- end
- if inpath ~= "-" then
- local handle, err = io.open(inpath, "r");
- io.input(handle or usage(err));
- end
- if outpath ~= "-" then
- local handle, err = io.open(outpath, "w");
- io.output(handle or usage(err));
- end
- -- Main program starts here
- local decode = (require("lunajson.decoder"))();
- local encode = (require("lunajson.encoder"))();
- local input = decode(io.input():read("*a"));
- local max_id = -1;
- local EMPTY = {};
- local blocknames = {};
- for blockname, _ in pairs(input) do
- blocknames[#blocknames+1] = blockname;
- end
- table.sort(blocknames, function(k1, k2)
- return input[k1].states[1].id < input[k2].states[1].id;
- end);
- for _, blockname in ipairs(blocknames) do
- local blockdata = input[blockname];
- local propnames = {}; -- property name sorting
- local lines = {}; -- used for dedup
- if ignore[blockname] ~= false then
- io.stderr:write(("%d - %s\n"):format(#blockdata.states, blockname))
- for propname, _ in pairs(blockdata.properties or EMPTY) do
- propnames[#propnames+1] = propname;
- end
- table.sort(propnames);
- for i = 1, #(blockdata.states or {}) do
- local state = blockdata.states[i];
- local line = ""
- line = line .. "FIXME" .. "\t" .. "FIXME" .. "\t" .. blockname;
- for i = 1, #propnames do
- local property = propnames[i];
- if ignore[blockname] and ignore[blockname][property] ~= nil then
- if ignore[blockname][property] then
- line = line .. "\t" .. property .. "\t" .. ignore[blockname][property];
- end
- else
- line = line .. "\t" .. property .. "\t" .. state.properties[property];
- end
- end
- if not lines[line] then
- lines[line] = true;
- -- io.write(state.id, "\t"); -- test
- io.write(line, "\n");
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement