{"id":19253135,"url":"https://github.com/techreborn/energy","last_synced_at":"2025-04-30T09:16:25.469Z","repository":{"id":42564512,"uuid":"203443610","full_name":"TechReborn/Energy","owner":"TechReborn","description":"An Energy API","archived":false,"fork":false,"pushed_at":"2025-03-16T15:42:19.000Z","size":260,"stargazers_count":85,"open_issues_count":1,"forks_count":13,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-30T09:16:14.429Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TechReborn.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-08-20T19:44:39.000Z","updated_at":"2025-04-24T13:33:34.000Z","dependencies_parsed_at":"2024-04-12T22:31:04.613Z","dependency_job_id":"9f35a08d-2151-4d78-ad98-5deb241fbed7","html_url":"https://github.com/TechReborn/Energy","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechReborn%2FEnergy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechReborn%2FEnergy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechReborn%2FEnergy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechReborn%2FEnergy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TechReborn","download_url":"https://codeload.github.com/TechReborn/Energy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251674589,"owners_count":21625646,"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":[],"created_at":"2024-11-09T18:29:36.115Z","updated_at":"2025-04-30T09:16:25.463Z","avatar_url":"https://github.com/TechReborn.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Energy\n\nAn Energy API for Fabric mods, originally written for TechReborn.\n\nUses Fabric's API Lookup and Transaction systems.\n\n# Conventions\nTo ensure good interop between all the mods using this API, here are a few conventions that should be followed.\n\n* Reference energy values\n  * 1 coal = 4000\n  * 1 plank = 750\n* The system is push-based.\n  * This means that power sources are responsible for pushing power to nearby machines.\n  * Machines and wires should NOT pull power from other sources.\n\n# Including the API in your project\n\nFind the latest versions [here](https://maven.fabricmc.net/teamreborn/energy/)\n\n- Version 3.x should be used for Minecraft 1.19.4 -\u003e 1.20.4\n- Version 4.0.x should be used for Minecraft 1.20.5 or later\n- Version 4.1.x should be used for Minecraft 1.21 or later\n- Version 4.2.x should be used for Minecraft 1.21.5 or later\n\nAdd the following into your dependencies block in build.gradle\n\n```groovy\ninclude modApi('teamreborn:energy:\u003clatest_version\u003e')\n```\n\n# Documentation\nThe API revolves around [`EnergyStorage`](src/main/java/team/reborn/energy/api/EnergyStorage.java).\nMake sure to check out the documentation.\n\nA few examples follow to get you started.\n\n## Implementing energy-containing blocks\nThe easiest way, with fixed capacity and insertion/extraction limits:\n```groovy\npublic class MyBlockEntity extends BlockEntity {\n    // Store a SimpleEnergyStorage in the block entity class.\n    public final SimpleEnergyStorage energyStorage = new SimpleEnergyStorage(CAPACITY, MAX_INSERT, MAX_EXTRACT) {\n        @Override\n        protected void onFinalCommit() {\n            markDirty();\n        }\n    };\n    \n    // Use the energy internally, for example in tick()\n    public void tick() {\n        if (!world.isClient \u0026\u0026 energyStorage.amount \u003e= 10) {\n            energyStorage.amount -= 10;\n            // do something with the 10 energy we just used.\n            markDirty();\n        }\n    }\n    \n    // Don't forget to save/read the energy in the block entity NBT.\n}\n\n// Don't forget to register the energy storage. Make sure to call this after you create the block entity type.\nBlockEntityType\u003cMyBlockEntity\u003e MY_BLOCK_ENTITY;\nEnergyStorage.SIDED.registerForBlockEntity((myBlockEntity, direction) -\u003e myBlockEntity.energyStorage, MY_BLOCK_ENTITY);\n```\n\n`SimpleSidedEnergyContainer` may be used if the I/O limits are side-dependent.\n\nIf you know what you are doing, you can also implement `EnergyStorage` directly, but in most cases that's not necessary.\nRefer to the documentation of this API, of the Transaction API and API Lookup for details.\n\n## Usage example (blocks)\nGet an energy storage:\n```groovy\n@Nullable\nEnergyStorage maybeStorage = EnergyStorage.SIDED.find(world, pos, direction);\n```\nGet an adjacent energy storage:\n```groovy\n// Known things\nWorld world; BlockPos currentPos; Direction adjacentDirection;\n// Get adjacent energy storage, or null if there is none\n@Nullable\nEnergyStorage maybeStorage = EnergyStorage.SIDED.find(world, currentPos.offset(adjacentDirection), adjacentDirection.getOpposite());\n```\nMove energy between two storages:\n```groovy\nEnergyStorage source, target;\n\nlong amountMoved = EnergyStorageUtil.move(\n        source, // from source\n        target, // into target\n        Long.MAX_VALUE, // no limit on the amount\n        null // create a new transaction for this operation \n);\n```\nTry to extract an exact amount of energy:\n```groovy\nEnergyStorage source;\nlong amountToUse;\n\n// Open a transaction: this allows cancelling the operation if it doesn't go as expected.\ntry (Transaction transaction = Transaction.openOuter()) {\n    // Try to extract, will return how much was actually extracted\n    long amountExtracted = source.extract(amountToUse, transaction);\n    if (amountExtracted == amountToUse) {\n        // \"Commit\" the transaction to make sure the change is applied.\n        transaction.commit();\n    } else {\n        // Doing nothing \"aborts\" the transaction, cancelling the change.\n    }\n}\n```\n\n## Creating chargeable items\nThe easiest way to create an item that can be charged by supported mods is by implementing `SimpleEnergyItem` on your item class.\nThe functions should be self-explanatory.\n\nFor more complex items, `EnergyStorage.ITEM` may be used directly.\nMake sure you read the documentation of `ContainerItemContext` if you go down that path.\n\n## Charging items\nCheck out how you can create a `ContainerItemContext`,\nand use it to query an `EnergyStorage` implementation with `EnergyStorage.SIDED`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechreborn%2Fenergy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechreborn%2Fenergy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechreborn%2Fenergy/lists"}