Skip to content

Commit

Permalink
Expose baritone component factory through API
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed May 26, 2021
1 parent fadc708 commit 843b839
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ baritone.settings().primaryTimeoutMS.set(2000L);
baritone.getCustomGoalProcess().setGoalAndPath(new GoalXZ(10000, 20000));
```

### Making your own non-player entity use Automatone
You need to register the relevant component for your entity, using the component factory provided
by Automatone:

```java
public final class MyComponents implements EntityComponentInitializer {
@Override
public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) {
registry.registerFor(MyEntity.class, IBaritone.KEY, BaritoneAPI.getProvider().componentFactory());
}
}
```
> Do not forget to add that class as an entrypoint with the `cardinal-components-entity` key !
```json
{
"entrypoints": {
"cardinal-components-entity": [
"my.package.MyComponents"
]
}
}
```
For more information on how components work, refer to [Cardinal Components API's documentation](https://github.com/OnyxStudios/Cardinal-Components-API/wiki).

## FAQ

### Can I use Automatone as a library in my mob mod?
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
------------------------------------------------------
Version 0.3.7
------------------------------------------------------
**Additions**
- Exposed an IBaritone factory to allow controlling other living entities through Automatone

------------------------------------------------------
Version 0.3.6
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with Baritone. If not, see <https://www.gnu.org/licenses/>.
#
mod_name = Automatone
mod_version = 0.3.6
mod_version = 0.3.7
maven_group = io.github.ladysnake

fabric_version = 0.34.0+1.16
Expand Down
3 changes: 3 additions & 0 deletions src/api/java/baritone/api/IBaritoneProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import baritone.api.command.ICommand;
import baritone.api.command.ICommandSystem;
import baritone.api.schematic.ISchematicSystem;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactory;
import net.minecraft.entity.LivingEntity;

/**
Expand Down Expand Up @@ -60,4 +61,6 @@ public interface IBaritoneProvider {
ISchematicSystem getSchematicSystem();

Settings getGlobalSettings();

<E extends LivingEntity> EntityComponentFactory<IBaritone, E> componentFactory();
}
3 changes: 2 additions & 1 deletion src/main/java/baritone/AutomatoneComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package baritone;

import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.cache.IWorldProvider;
import baritone.api.selection.ISelectionManager;
Expand All @@ -39,7 +40,7 @@ public final class AutomatoneComponents implements EntityComponentInitializer, W
public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) {
registry.registerFor(LivingEntity.class, IPlayerController.KEY, entity -> DummyEntityController.INSTANCE);
registry.registerFor(LivingEntity.class, ISelectionManager.KEY, SelectionManager::new);
registry.registerFor(PlayerEntity.class, IBaritone.KEY, Baritone::new);
registry.registerFor(PlayerEntity.class, IBaritone.KEY, BaritoneAPI.getProvider().componentFactory());
registry.registerFor(ServerPlayerEntity.class, IPlayerController.KEY, ServerPlayerController::new);
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/baritone/BaritoneProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import baritone.command.CommandSystem;
import baritone.utils.SettingsLoader;
import baritone.utils.schematic.SchematicSystem;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactory;
import net.minecraft.entity.LivingEntity;

/**
Expand Down Expand Up @@ -74,4 +75,9 @@ public ISchematicSystem getSchematicSystem() {
public Settings getGlobalSettings() {
return this.settings;
}

@Override
public <E extends LivingEntity> EntityComponentFactory<IBaritone, E> componentFactory() {
return Baritone::new;
}
}

0 comments on commit 843b839

Please sign in to comment.