your current location:首页 > news>Energy Minecraft

Energy Minecraft

2024-12-12 09:27:58|Myriagame |source:minecraft skins

Brief introduction

Energy API developed by the Tech Reborn team.

It is provided in the form of jar in jar, so there is no need to install it independently.

The following is translated from github:

energy

A energy API on Fabric was originally used for the Tech Reborn.

Use Fabric's lookup API and Transaction API.

Agreed

In order to ensure that the MOD of this API can be well compatible, the following agreement must be followed.

Energy value standard reference:

1X coal = 4000;

1x wooden board = 750.

Power grid based on passive transportation:

That is, the power supply is responsible for transporting the energy to the machine;

The machine and cable should not be requested from the power supply.

Add this API to your project

The final version can be found here.

Add the following content to your build.gradle dependenncies

 Include Modapi ('Teamreborn: Energy: ') {Exclude (Group: "Net.fabricmc.fabric-API")} 

document

The function of this API revolves around EnergyStorage, please check the document.

Here are a few simple cases.

Implement the energy storage block interface

The easiest way, but there are capacity and insert/insert/pull out restrictions:

 Public Class MyBlockIntity Extends blockity {// Create a SimpleNerGyStorage in the square entity // Store a SimplenerGyStorage In the Bl OCK Entity Class.) {@Override Protected void OnfinalCommit () {MarkDirty ();}; // Consume energy inside the square entity, such as in the Tick method.// Use the Energy Internet, for Example in Tick () Public Void Tick () {if (! World.isClient && EnergyStorage.amount> = 10) {Energyst ORAGE.AMOUNT- = 10; // Use 10 points we just consumeWhat does energy do.

// Do something with the 10 Energy We just used. MarkDirty ();}} // Do not forget to save/read the energy in the entity NBT of the block of the block.//D'T forget to save/Read the Energy in the Block Entity nbt.} // Do not forget the registered energy storage device to ensure that this calls this after creating a block -like entity type.// Don't forget to register the Energy Storage. Makes to call this after you create the block entity type.blockentityType MyBlockentity.enerGyStorage, My_block_entity)

You can use SimpleSidednerGyContainer when you need to determine the I/O state.

If you know what you are doing, you can also directly implement EnergyStorage, but in most cases, this is unnecessary.

For details, please refer to the documents of this API, lookup API and Transaction API.

Use case (block)

Get a energy storage device

@nullablenerGystorage maybestorage = EnergyStorage.Sided.find (world, pos, direction); 

Get an adjacent energy storage device

 // Knowing quantity.// Known Thingsworld World; Blockpos Currentpos; Direction AdjacentDirection; // Obtain adjacent energy storage, if not, it is empty.// getjacent Energy Storage, or null if there is none@nullablenerGyStorage maybestorage = EnergyStorage.Sided.find (world, CurrenTPSET (ApplyDiredire CTION), AdjacentDirection.getopposite ()); 
Inter -transfer energy

 EnergyStorage Source, Target; Long amountmoved = EnergyStorageutil.move (source, // From Source Target, // Energy acceptance side // into target long.max_value,//Maximum energy limit // no limit on the amount null // create a new transaction // create a new transaction for this operation) for this operation; 

Try to extract an accurate energy value

 EnergyStorage Source; long amounttous; // Open a transaction: If the operation does not achieve the expected effect, the operation is canceled.// Open a transaction: This allown cannot. // Try extraction and return the actual extraction.// Try to extract, Will Return How Much Was Actually Extracted. Long amounttextract = source.extract (amountttous, transaction); if (amou NTEXTRACTED == amounttous) {// "Submit" transaction to ensure that the change is applied.// "Commit" the transaction to make ance the change is applied. Transaction.Commit ();} Else {// "stop" transaction and cancel the change.// Doing Nothing "Aborts" The Transaction, Cancelling the Change.}} 
Create a capable item

The easiest way to create a supporting MODS charging item is to implement SimpleEnergyItem on your item category. These features should be self -evident.

For more complicated items, you can use EnergyStorage.Item directly.If you choose to do this, please read the document for the ContaineriteMContext.

Energy storage item

See how you create a containeriteMContext and use it to find an EnergyStorage implementation with EnergyStorage.SIDED.