Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make setting crafting components from KJS more ergonomic. #2639

Draft
wants to merge 1 commit into
base: 1.20.1
Choose a base branch
from

Conversation

tomprince
Copy link
Contributor

What

Javascript objects only support strings as keys, so allow passing objects (i.e maps) with short tier names as keys for defining crafting components.

Outcome

Before (note in particular the need to import Map from java, rather than native JS syntax):

const Map = Java.loadClass("java.util.Map");

GTCEuStartupEvents.craftingComponents(event => {

    //Make LuV+ electrolyzer wires not osmium for funsies :)
    let wireElectricMap = {};
    event.modify(CraftingComponent.WIRE_ELECTRIC, Map.of(
        GTValues.LuV, UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.VanadiumGallium),
        GTValues.ZPM, UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.NaquadahAlloy),
        GTValues.UV, UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.get('sculk_superconductor')),
        GTValues.UHV, UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.get('activated_netherite')),
        GTValues.UEV, UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.Holmium),
        GTValues.UIV, UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.get('monium')),
    ));
})

After:

GTCEuStartupEvents.craftingComponents(event => {

    //Make LuV+ electrolyzer wires not osmium for funsies :)
    event.modify(CraftingComponent.WIRE_ELECTRIC, {
        LuV: UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.VanadiumGallium),
        ZPM: UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.NaquadahAlloy),
        UV: UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.get('sculk_superconductor')),
        UHV: UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.get('activated_netherite')),
        UEV: UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.Holmium),
        UIV: UnificationEntry(TagPrefix.wireGtSingle, GTMaterials.get('monium')),
    });
});

Potential Compatibility Issues

The functions now accept maps with either numbers (as now) or strings (which can be from native javascript objects), so the change should be backwards compatible.

@tomprince
Copy link
Contributor Author

I want to have a look at improving the error handling somewhat, still.

@@ -142,6 +145,9 @@ public static int[] tiersBetween(int minInclusive, int maxInclusive) {
public static final String[] VN = new String[] { "ULV", "LV", "MV", "HV", "EV", "IV", "LuV", "ZPM", "UV", "UHV",
"UEV", "UIV", "UXV", "OpV", "MAX" };

public static final Map<String, Integer> RVN = IntStream.range(0, VN.length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object2IntMap to avoid boxing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what does RVN stand for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably reverse voltage names, no?

@screret screret added the type: refactor Suggestion to refactor a section of code label Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor Suggestion to refactor a section of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants