{"id":15015255,"url":"https://github.com/alexiil/libnetworkstack","last_synced_at":"2025-04-12T09:14:16.564Z","repository":{"id":36688261,"uuid":"189762865","full_name":"AlexIIL/LibNetworkStack","owner":"AlexIIL","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-13T04:38:33.000Z","size":626,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"0.10.x-1.20.x","last_synced_at":"2025-04-12T09:14:08.598Z","etag":null,"topics":["fabricmc","library","minecraft","minecraft-fabric","minecraft-mod","mod"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexIIL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-01T17:57:18.000Z","updated_at":"2023-11-10T09:58:46.000Z","dependencies_parsed_at":"2024-06-01T06:46:16.474Z","dependency_job_id":"e6323f9e-497f-4a54-88bb-1b34053b882d","html_url":"https://github.com/AlexIIL/LibNetworkStack","commit_stats":{"total_commits":115,"total_committers":5,"mean_commits":23.0,"dds":"0.31304347826086953","last_synced_commit":"6fe7c8755cbd5bab03a7ccab0a1ab59a94b57851"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIIL%2FLibNetworkStack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIIL%2FLibNetworkStack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIIL%2FLibNetworkStack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIIL%2FLibNetworkStack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexIIL","download_url":"https://codeload.github.com/AlexIIL/LibNetworkStack/tar.gz/refs/heads/0.10.x-1.20.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248543840,"owners_count":21121838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fabricmc","library","minecraft","minecraft-fabric","minecraft-mod","mod"],"created_at":"2024-09-24T19:46:40.545Z","updated_at":"2025-04-12T09:14:16.541Z","avatar_url":"https://github.com/AlexIIL.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LibNetworkStack\n\nThis is a library mod for the [Fabric](https://fabricmc.net/) API, based around [Minecraft](https://minecraft.net).\n\n## Maven\n\nCurrently you can use this by adding this to your build.gradle:\n\n```\nrepositories {\n    maven {\n        name = \"AlexIIL\"\n        url = \"https://maven.alexiil.uk/\"\n    }\n}\n\ndependencies {\n    modImplementation \"alexiil.mc.lib:libnetworkstack-base:0.7.1\"\n}\n```\n\nPlease use the javadoc list [here](https://alexiil.uk/javadoc) to determine the right LNS version for your minecraft version.\n\n## Getting Started\n\nYou can either look at the [wiki](https://github.com/AlexIIL/LibNetworkStack/wiki) for a brief overview, or look at [SimplePipes](https://github.com/AlexIIL/SimplePipes) source code for a use-case mod that uses this. To get help you can either open an issue here, or ping AlexIIL on the fabric or CottonMC discord servers.\n\n## A simple example\n\nFor example if you wanted to send data from your custom BlockEntity called \"ElectricFurnaceBlockEntity\", you would do this:\n\n```java\n\nimport alexiil.mc.lib.net.ActiveConnection;\nimport alexiil.mc.lib.net.IMsgReadCtx;\nimport alexiil.mc.lib.net.IMsgWriteCtx;\nimport alexiil.mc.lib.net.InvalidInputDataException;\nimport alexiil.mc.lib.net.NetByteBuf;\nimport alexiil.mc.lib.net.NetIdDataK;\nimport alexiil.mc.lib.net.NetIdDataK.IMsgDataWriterK;\nimport alexiil.mc.lib.net.NetIdSignalK;\nimport alexiil.mc.lib.net.ParentNetIdSingle;\nimport alexiil.mc.lib.net.impl.CoreMinecraftNetUtil;\nimport alexiil.mc.lib.net.impl.McNetworkStack;\n\npublic class ElectricFurnaceBlockEntity extends BlockEntity {\n    // All base code left out\n    public static final ParentNetIdSingle\u003cElectricFurnaceBlockEntity\u003e NET_PARENT;\n    public static final NetIdDataK\u003cElectricFurnaceBlockEntity\u003e ID_CHANGE_BRIGHTNESS;\n    public static final NetIdSignalK\u003cElectricFurnaceBlockEntity\u003e ID_TURN_ON, ID_TURN_OFF;\n\n    static {\n        NET_PARENT = McNetworkStack.BLOCK_ENTITY.subType(\n            // Assuming the modid is \"electrical_nightmare\"\n            ElectricFurnaceBlockEntity.class, \"electrical_nightmare:electric_furnace\"\n        );\n        // We don't need to re-specify the modid for this because the parent already did\n        // and we don't expect any other mods to add new id's.\n        ID_CHANGE_BRIGHTNESS = NET_PARENT.idData(\"CHANGE_BRIGHTNESS\").setReceiver(\n            ElectricFurnaceBlockEntity::receiveBrightnessChange\n        );\n        ID_TURN_ON = NET_PARENT.idSignal(\"TURN_ON\").setReceiver(ElectricFurnaceBlockEntity::receiveTurnOn);\n        ID_TURN_OFF = NET_PARENT.idSignal(\"TURN_OFF\").setReceiver(ElectricFurnaceBlockEntity::receiveTurnOff);\n    }\n\n    /** Used for rendering - somehow. */\n    public int clientBrightness;\n    public boolean clientIsOn;\n\n    public ElectricFurnaceBlockEntity() {\n        super(null);\n    }\n\n    /** Sends the new brightness, to be rendered on the front of the block.\n     *  This should be called on the server side.\n     * \n     * @param newBrightness A value between 0 and 255. */\n    protected final void sendBrightnessChange(int newBrightness) {\n        for (ActiveConnection connection : CoreMinecraftNetUtil.getPlayersWatching(getWorld(), getPos())) {\n            ID_CHANGE_BRIGHTNESS.send(connection, this, new IMsgDataWriterK\u003cElectricFurnaceBlockEntity\u003e() {\n\n                // In your own code you probably want to change this to a lambda\n                // but the full types are used here for clarity.\n\n                @Override\n                public void write(ElectricFurnaceBlockEntity be, NetByteBuf buf, IMsgWriteCtx ctx) {\n                    ctx.assertServerSide();\n\n                    buf.writeByte(newBrightness);\n                }\n            });\n        }\n    }\n\n    /** Sends the new on/off state, to be rendered on the front of the block.\n     *  This should be called on the server side. */\n    protected final void sendSwitchState(boolean isOn) {\n        for (ActiveConnection connection : CoreMinecraftNetUtil.getPlayersWatching(getWorld(), getPos())) {\n            (isOn ? ID_TURN_ON : ID_TURN_OFF).send(connection, this);\n        }\n    }\n\n    protected void receiveBrightnessChange(NetByteBuf buf, IMsgReadCtx ctx) throws InvalidInputDataException {\n        // Ensure that this was sent by the server, to the client (and that we are on the client side)\n        ctx.assertClientSide();\n\n        this.clientBrightness = buf.readUnsignedByte();\n    }\n\n    protected void receiveTurnOn(IMsgReadCtx ctx) throws InvalidInputDataException {\n        // Ensure that this was sent by the server, to the client (and that we are on the client side)\n        ctx.assertClientSide();\n\n        this.clientIsOn = true;\n    }\n\n    protected void receiveTurnOff(IMsgReadCtx ctx) throws InvalidInputDataException {\n        // Ensure that this was sent by the server, to the client (and that we are on the client side)\n        ctx.assertClientSide();\n\n        this.clientIsOn = false;\n    }\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexiil%2Flibnetworkstack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexiil%2Flibnetworkstack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexiil%2Flibnetworkstack/lists"}