Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

LangGen - a Minecraft Language Generator


Simon_kungen
 Share

Recommended Posts

Introduction:

 

This is not really a tutorial per se, but as this fits the bill the best, here we are.

 

I got sick of having to manually create new lines for, and every, new item and block in the language file. Sure copy-pasting and run a replace search did kind of solve the issue, but it was still very tedious. So I sat down and made a generator tool written in JavaScript for Node.js. And that is what this post is about.

 

Requirements:

 

You will need Node.js installed on your system if you want to run it locally, but I'm sure there is an online version you can run from too. Anyways, the program needs a Json blueprint from which it will generate all the finished language translations. A generic one is in a spoiler down here:

 

Tutorial:

 

{

    "domain": "examplemod",

    "types": [
        { "ingot" : "%s Ingot" },
        { "nugget" : "%s Nugget" },
        { "dust" : "%s Dust" },
        { "plate" : "%s Plate" },
        { "gear" : "%s Gear" },
        { "block" : "%s Block", "flag" : "block" },
        { "frame" : "%s Frame", "flag" : "block" },
        { "ore" : "%s Ore", "flag" : "ore" }
    ],

    "elements": [
        { "silver" : "Silver" },
        { "gold" : "Gold",
            "filter": [ "ingot","nugget","block","ore" ]
        },
        { "copper" : "Copper" },
        { "iron" : "Iron",
            "filter": [ "ingot","nugget","block","ore" ]
        },
        { "lead" : "Lead" },
        { "tin" : "Tin" }

    ]
}

 

Ok, so what's going on here? The "domain" is your mod's name, that can be anything. Then there are the array "types", it is what type of item you want to make a translation of off. It first needs a name as the key, and then the translation. It is important you have the "%s" symbol in there as that is what is going to be replaced with an entry in the "types" array. You can change however you want of the translated key, as long as it has the "%s" in it. A second optional argument called "flag" can be used. Not sure if you're like me, but I do like to have some structure in my language files, so types with the same flag will be grouped in the output file (if enabled). And if you have it be the same in the program options' blockKeywords array it will automatically make it a block contrary to item. By default, it will make types with the flag "block" or "ore" to be blocks in the output file.

 

In the "elements" array is what materials you want them in. It first needs a key and then a translated version of it. There is an optional argument too called "filter". It is an array of types you don't want translated, ex. you might not want to make a translation for Iron Ingot as Minecraft already adds that, so adding "ingot" in the filter array it will not generate in the output file. Something to note is if it has the keyword "none" it will skip over it entirely, might only be useful in very particular cases like if you go by a pre-decided dictionary.

 

 

In the program (index.js) there are a few options you can tweak, but I have already explained what they do in the file so I'm going to skip that and explain how on to set up the program:

After you've extracted the program you should just have to open the command prompt and type "node .". "node" is the program, and the "." tells it to use the package.json in that directory. If everything worked as intended it should have created a new file in "output/" with the same name as the input file in "input/".

 

Technical part:

 

When creating the language key, it first decides between using "item." or "block.", thereafter the domain. The item/block key name is generated by first using the key name, then dividing it with a "_" and the type key. Example:

Domain: "buildcraftcore"

Type: "gear"

Element: "gold"

"item.buildcraftcore.gold_gear" : "Gold Gear"

 

Download:

 

LangGen.zip

 

The plain index.js file

/**
 * A tool to generate language translations for blocks and items for my Minecraft mods
 * with similar names from a Json file blueprint. A high degree of customization of the Json
 * is possible to generate a large amount of different translations with language keys in specified order
 * ready for file transfer or manually copy-paste into desired language file, written in JavaScript in Node.js.
 *
 * By Simon
 */

const fs = require('fs');


const lang          = 'en_us.json'; // Change this to the desired language file name in input/.
const spacing       = 2;            // The desired spacing in the output file (recom. 2 or 4).
const separated     = true;         // If the flagged types should be separated or mixed in the output file.
const logging       = false;        // Whenever it should write out the language key to the console.
const blockKeywords = [             // If a flag matches a word here it will change the language key to be a block.
    'block', 'ore'
]

//////////////////////// Don't edit below this unless you know what you're doing ////////////////////////

fs.readFile('input/' + lang, (err,data) => {
    if (err) throw err;
    const json = JSON.parse(data);

    let JSONObjects = [{}];

    json.elements.forEach(element => {

        for (let i in json.types) {

            let shouldSkip = false;
            if (element.filter)
                for (var j=0;j<element.filter.length;j++) {
                    if (element.filter[j] == Object.keys(json.types[i])[0] || element.filter[j] == 'none') {
                        shouldSkip = true;
                        break;
                    }
                }
            

            if (shouldSkip) continue;

            let translation = json.types[i][Object.keys(json.types[i])[0]];
            let keyword = json.domain + "." + Object.keys(element)[0] + "_" + Object.keys(json.types[i])[0];

            translation = translation.replace("%s", element[Object.keys(element)[0]]);

            let t = blockKeywords.includes(json.types[i].flag) ? 'block.' : 'item.';

            if (logging) {
                console.log(line(t + keyword, translation));
            }


            if (separated) {
                let index = 0;
                if (json.types[i].flag) {
                    index = json.types[i].flag;
                    if (JSONObjects[index] == undefined) {
                        JSONObjects[index] = {};
                    }
                }                
                JSONObjects[index][t + keyword] = translation;
            }
            else
                JSONObjects[0][t + keyword] = translation;
        }
    });

    fs.readFile('output/' + lang, (err, data) => {

        const text = JSON.stringify(separated ? merge(JSONObjects) : JSONObjects[0], null, spacing);

        if (!err)
            if (text == data.toString()) {
                console.log('No changes to output/' + lang);
                return;
            }
        
        fs.writeFileSync('output/' + lang, text);
        console.log('Wrote to output/' + lang);
    });
});
function line(a,b) { return "\"" + a + "\" : \"" + b + "\"" }
function merge(a) { const r = {};Object.keys(a).forEach(j => Object.keys(a[j]).forEach(key => r[key] = a[j][key]));return r; }

 

Edited by Simon_kungen
Spoilers are bugged here for some reason, removed them*.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Thanks for the help everybody! I tried this and although the block did register, the fluid just appears as a flat plane you can only see if you break the block under it. I tried debugging it as much as I could but alas I couldn't solve it Here is the code for my "fixed" liquidblock as suggested by Luis_ST: package com.hotmail.majdroaydi.minitech.blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.sounds.SoundEvent; import net.minecraft.tags.FluidTags; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import java.util.Optional; import java.util.function.Supplier; public class ForgeLiquidBlock extends LiquidBlock { public ForgeLiquidBlock(Supplier<? extends FlowingFluid> supplier, Properties properties) { super(supplier, properties); } @Override public VoxelShape getCollisionShape(BlockState p_54760_, BlockGetter p_54761_, BlockPos p_54762_, CollisionContext p_54763_) { return p_54763_.isAbove(STABLE_SHAPE, p_54762_, true) && p_54760_.getValue(LEVEL) == 0 && p_54763_.canStandOnFluid(p_54761_.getFluidState(p_54762_.above()), getFluid()) ? STABLE_SHAPE : Shapes.empty(); } @Override public boolean isPathfindable(BlockState p_54704_, BlockGetter p_54705_, BlockPos p_54706_, PathComputationType p_54707_) { return !getFluid().is(FluidTags.LAVA); } @Override public boolean skipRendering(BlockState p_54716_, BlockState p_54717_, Direction p_54718_) { return p_54717_.getFluidState().getType().isSame(getFluid()); } @Override public void onPlace(BlockState p_54754_, Level p_54755_, BlockPos p_54756_, BlockState p_54757_, boolean p_54758_) { if (this.shouldSpreadLiquid(p_54755_, p_54756_, p_54754_)) { p_54755_.getLiquidTicks().scheduleTick(p_54756_, p_54754_.getFluidState().getType(), getFluid().getTickDelay(p_54755_)); } } @Override public BlockState updateShape(BlockState p_54723_, Direction p_54724_, BlockState p_54725_, LevelAccessor p_54726_, BlockPos p_54727_, BlockPos p_54728_) { if (p_54723_.getFluidState().isSource() || p_54725_.getFluidState().isSource()) { p_54726_.getLiquidTicks().scheduleTick(p_54727_, p_54723_.getFluidState().getType(), getFluid().getTickDelay(p_54726_)); } //return super.updateShape(p_54723_, p_54724_, p_54725_, p_54726_, p_54727_, p_54728_); return p_54723_; // Calling super.updateShape will just call LiquidBlock's updateShape, not what we are looking for! Thankfully, Block.updateShape, simply enough, just returns the first parameter. } @Override public void neighborChanged(BlockState p_54709_, Level p_54710_, BlockPos p_54711_, Block p_54712_, BlockPos p_54713_, boolean p_54714_) { if (this.shouldSpreadLiquid(p_54710_, p_54711_, p_54709_)) { p_54710_.getLiquidTicks().scheduleTick(p_54711_, p_54709_.getFluidState().getType(), getFluid().getTickDelay(p_54710_)); } } private boolean shouldSpreadLiquid(Level p_54697_, BlockPos p_54698_, BlockState p_54699_) { if (getFluid().is(FluidTags.LAVA)) { boolean flag = p_54697_.getBlockState(p_54698_.below()).is(Blocks.SOUL_SOIL); for(Direction direction : POSSIBLE_FLOW_DIRECTIONS) { BlockPos blockpos = p_54698_.relative(direction.getOpposite()); if (p_54697_.getFluidState(blockpos).is(FluidTags.WATER)) { Block block = p_54697_.getFluidState(p_54698_).isSource() ? Blocks.OBSIDIAN : Blocks.COBBLESTONE; p_54697_.setBlockAndUpdate(p_54698_, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(p_54697_, p_54698_, p_54698_, block.defaultBlockState())); this.fizz(p_54697_, p_54698_); return false; } if (flag && p_54697_.getBlockState(blockpos).is(Blocks.BLUE_ICE)) { p_54697_.setBlockAndUpdate(p_54698_, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(p_54697_, p_54698_, p_54698_, Blocks.BASALT.defaultBlockState())); this.fizz(p_54697_, p_54698_); return false; } } } return true; } private void fizz(LevelAccessor p_54701_, BlockPos p_54702_) { p_54701_.levelEvent(1501, p_54702_, 0); } @Override public ItemStack pickupBlock(LevelAccessor p_153772_, BlockPos p_153773_, BlockState p_153774_) { if (p_153774_.getValue(LEVEL) == 0) { p_153772_.setBlock(p_153773_, Blocks.AIR.defaultBlockState(), 11); return new ItemStack(getFluid().getBucket()); } else { return ItemStack.EMPTY; } } @Override public Optional<SoundEvent> getPickupSound() { return getFluid().getPickupSound(); } } The code for my OilFluid can be found above.
    • Whoops! Sorry, my fault. But yes, a block entity (tile entity in 1.16-) *is* needed for storing data (i.e. furnace). But I think what OP is doing is making an item combiner, which doesn't need one
    • Looking to work with reliable Fabric & Forge developers to produce original mods for use on my YouTube channel! We'll be regularly working together and you'll be given a detailed brief for each commission that outlines exactly what I want. From there, you can give me a price that fits the scope of the project and we can get to work :thumbsup: Because these commissions are only for YouTube videos, you're essentially making vertical-slices / proof-of-concepts. They can have bugs, you can take shortcuts & we can use video editing to hide bugs & achieve some effects. With that in mind, turnaround speed depends on project complexity but for an average commission I'd expect delivery two days - five days Send me a email at either lmaololtbhhonest@gmail.com OR Business@tbhhonest.com if you're interested! preview of channel: https://imgur.com/a/bOVkiUo LINK:  https://www.youtube.com/channel/UCnwo3X3eCrUp7N1DZPc-MGQ  
    • If you want a tiny fraction of offset, use float.epsilon. 0.01 will actually be noticeable. It's about 1/6th of a texture pixel.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.