Giter Club home page Giter Club logo

resource-pack-converter's Introduction

Resource Pack Converter

CircleCI npm License semantic-release Gitmoji

๐Ÿšง Still work in progress...

The RPC (Resource Pack Converter) is a npm package which can convert a Minecraft: Java Edition resource pack from any version to another version.

Usage

You can use it via the Command Line Tool or importing it to your project.

Use via Command Line Tool

  1. Make sure you have nodejs installed on your computer.
  2. Execute npm i resource-pack-converter -g in your command line (e.g. PowerShell, cmd, bash, etc.)
  3. TODO

Import it to your Project

  1. Installation.
    npm i resource-pack-converter
  2. Import.
    import { convert } from 'resource-pack-converter'
  3. TODO

File Structure

  • src: Source code written in TypeScript.
  • lib: Output JavaScript files.
  • uti: Some useful tools while coding.
    • analyzer.js: An resource pack analyzer which can find the differences (e.g. file names) between two resource packs (only support folders) and generate conversion files. Use
    npm run uti:analyzer ${fromDir} ${toDir} ${outDir}
    to analyze differences between ${fromDir} and ${toDir}. The result will be stored in uti/analyzer/${outDir}. e.g.
    npm run uti:analyzer uti/input/1.6/ uti/input/1.7/ 1.6-1.7.json

How does it Work

Overview

The RPC will decompressed the input resource pack if it's compressed, and then execute all adapters orderly for each file in the resource pack according to specific conversion. All adapted files will be put in specific path under ${outDir}, so nothing will be changed in the source resource pack.

Adapters

Adapters carry out operations for single file in the resource pack, e.g. renaming, scaling image, changing text content, etc. All adapters are written in TypeScript and should implement the Adapter interface. They are located in ./src/adapters/.

Adapters may be referenced in conversions.

Conversions

A Conversion contains a set of adapters. It's stored in ./src/conversions/.

  • The root tag.
    • adapters: (Required) Array. Contains a set of adapters.
    • from: (Required) String. Specifies the game version which the conversion starts from.
    • to: (Required) String. Specifies the game version which the conversion ends with.

Contributing

I'm thrilled to hear that you'd like to contribute to this project. It's no doubt that the converter will be better with your help!

  1. Fork this this repo and clone it to your local.

  2. Install dependencies.

    npm i

  3. Edit files in ./src.

  4. If you add new features, it's strongly recommend to write tests for them. All tests should be put under ./src/test.

  5. Commit your changes by npm run commit and then push them to the origin.

  6. Open a Pull Request. The circle CI will build and test your changes automatically.

There must be lots of mistakes and bad practice in this repository. If you find something not good or not sure whether it's not good, please don't hesitate to tell me!

resource-pack-converter's People

Contributors

renovate-bot avatar spgoding avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

langyo

resource-pack-converter's Issues

Handle clock.

Warn Useless File:

  • assets/minecraft/textures/items/clock.png.mcmeta

If model minecraft:item/clock doesn't exist

Split texture minecraft:items/clock.

Else

Split model minecraft:item/clock and the texture defined in it.

Change the PathAdapter

The new PathAdapter should still provide methods to change paths (or we call the namespaced strings) of specific files.

The new PathAdapterOptions should be like this:

interface PathAdapterOptions {
    operations: {
        filter: FileFilter,
        set: string
    }[]
}

class FileFilter {
    constructor(
        private readonly type: string,
        private readonly namespacedIDs: RegExp[],
        private readonly extensions: string[]
    ) { }

    public test() {
        throw new Error('Method not implemented.')
    }
}

So now we can change the previous PathAdapter constructions defined in conversions to this:

new PathAdapter({
    operations: [
            filter: new FileFilter('textures', [/^minecraft:items\/fish_raw$/], ['png', 'png.mcmeta']),
            set: 'minecraft:items/fish_cod_raw'
        }
    ]
})

Add adapter factories.

When a conversion begin, get an object called whole containing all blockstates and models.

Then, run adapter factories to get adapters. An adapter factory will return adapter(s) according to the whole. Adapters provided by adapter factories will be appended in the adapters filed of the conversion.

e.g. The ClockAdapterFactory will return an ClockAdapter which will split specfic textute defined in model minecraft:item/clock.

Combine models.

Combine models to a simple model for hences, glass panes, etc.

I18n of the logger

It will also be great to generate human-readable documents about what an adapter does.

Change PathAdapter logic.

We have changed PathAdapter before in #7, but that's incompleted. Since models were introduced in JE1.8 and blockstates were introduced in JE1.9, the namespaced IDs of textures are not fixed anymore.

In JE1.8, models determine the namespaced IDs of textures. In JE1.9, blockstates determine the namespaced IDs of block models.

So when wiring the conversion of JE1.8 into JE1.9, what we should do is not to change textures locations, but to change the locations of models accordingly. Only if the model is omitted in the resource pack, we should apply the changes of models in vanilla resource pack to the textures.

So, don't split texture minecraft:items/clock hardcodely, but to split textures defined in model minecraft:item/clock. To implement this, we need an object like this:

{
    "models": {
        "minecraft:item/clock": {
            "parent": "builtin/clock",
            "textures": {
                "...": "....."
            }
        },
       "...": {}
    }
}

And we merge the model definitions in input resource pack (identified with "RPC$isReplaced": true) with the object. At last we find out the specific model, check if the parent is set to builtin/clock, get the namespaced ID of clock texture, split textures (and models if RPC$isReplaced).

Rename File to Resource in utils

/**
 * Reprensets an resource in the resource pack.
 */
export interface Resource {
    /**
     * The content of the resource.
     */
    content: Buffer,
    /**
     * The type of the resource.
     */
    type: string
    /**
     * The namespaced string of the resource.
     */
    namespacedString: string
}

Handle compass textures.

Warn Useless Files:

  • assets/minecraft/models/item/compass.json
  • assets/minecraft/textures/items/compass.png.mcmeta

Split Files:

  • assets/minecraft/textures/items/compass.png to /minecraft/textures/items/compass_${x}.png.

See also: #9

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.