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

Tool items update #109

Open
mineLdiver opened this issue Apr 29, 2024 · 3 comments · May be fixed by #133
Open

Tool items update #109

mineLdiver opened this issue Apr 29, 2024 · 3 comments · May be fixed by #133
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@mineLdiver
Copy link
Member

Current StationAPI tool items system is convoluted and broken.

There aren't solid plans on how to reimplement the system.

Discussion is welcome.

@mineLdiver mineLdiver moved this to 2.0-alpha.4 in StationAPI Apr 29, 2024
@mineLdiver mineLdiver modified the milestones: 2.0-alpha.4, 2.0-alpha.3 Apr 29, 2024
@mineLdiver mineLdiver added the enhancement New feature or request label May 1, 2024
@mineLdiver
Copy link
Member Author

My proposed layout:
image

The idea is that each level node is only aware of its predecessors and can have multiple of them.

In code, if tool material only specifies a numeric mining level, it'll stick to the default branch (vanilla + extended).
If a level node is specified, it overrides the numeric mining level, binding the tool material to the appropriate place in the graph.

Any level node can be modified at any time to get more predecessors, including vanilla nodes.

Feedback is greatly appreciated.

@mineLdiver
Copy link
Member Author

mineLdiver commented May 1, 2024

Draft implementation without extended levels
import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

public class Main {
    static MiningNode[] VANILLA_NODES = new MiningNode[4];
    static {
        var base = new MiningNode(Optional.empty(), Set.of());
        var stone = new MiningNode(Optional.of(new BlockTag("needs_stone_tool")), set(base));
        var iron = new MiningNode(Optional.of(new BlockTag("needs_iron_tool")), set(stone));
        var diamond = new MiningNode(Optional.of(new BlockTag("needs_diamond_tool")), set(iron));
        VANILLA_NODES[0] = base;
        VANILLA_NODES[1] = stone;
        VANILLA_NODES[2] = iron;
        VANILLA_NODES[3] = diamond;
    }

    @SafeVarargs
    static <T> Set<T> set(T... elements) {
        return new HashSet<>(Arrays.asList(elements));
    }

    public static void main(String[] args) {
        var myLevel1 = new MiningNode(Optional.of(new BlockTag("needs_my_tool_level_1")), set(VANILLA_NODES[1]));
        var myLevel2 = new MiningNode(Optional.of(new BlockTag("needs_my_tool_level_2")), set(myLevel1));
        var myLevel3 = new MiningNode(Optional.of(new BlockTag("needs_my_tool_level_3")), set(myLevel2));
        VANILLA_NODES[2].predecessors().add(myLevel3);
        System.out.println(VANILLA_NODES[1].contains(new BlockTag("needs_my_tool_level_2")));
        System.out.println(VANILLA_NODES[2].contains(new BlockTag("needs_my_tool_level_2")));
    }

    record ToolMaterial(
            int miningLevel,
            int itemDurability,
            float miningSpeed,
            int attackDamage,
            Optional<MiningNode> miningNode
    ) {
        MiningNode getNode() {
            return miningNode.orElseGet(() -> VANILLA_NODES[miningLevel]);
        }
    }

    record MiningNode(
            Optional<BlockTag> tag,
            Set<MiningNode> predecessors
    ) {
        boolean contains(BlockTag otherTag) {
            return (tag.isPresent() && tag.get().equals(otherTag)) || predecessors.stream().anyMatch(predecessor -> predecessor.contains(otherTag));
        }
    }

    record BlockTag(String id) {}
}

@mineLdiver
Copy link
Member Author

Actual implementation turned out to be way easier thanks to tags that basically replace the MiningNode and all related logic.

Implementation is being worked on at https://github.com/ModificationStation/StationAPI/tree/2.0-alpha.3

@mineLdiver mineLdiver self-assigned this May 6, 2024
@mineLdiver mineLdiver linked a pull request Nov 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

1 participant