-
Notifications
You must be signed in to change notification settings - Fork 6
Manhunt API
This page will document the Manhunt API and the features it provides.
- Allows mods to hook into the compass updating process and modify it.
- Allows mods to cancel the speedrunner glowing.
- I recommend to make your mod depend on
manhunt-api
in yourfabric.mod.json
like so:
{
// ...
"depends": {
// ...
"manhunt-api": "~1.0"
}
}
Start by registering a CompassUpdateCallback
event in your mod initializer like so:
@Override
public void onInitialize() {
// ... your other code here
CompassUpdateCallback.EVENT.register((oldStack, newStack) -> {
// Code here
});
}
Your IDE will probably scream at you at this stage, because you didn't return a value from the lambda. The CompassUpdateCallback
interface requires you to return an ItemStack
.
For now, you can return newStack
.
Parameter explanation:
-
oldStack
- The oldest
ItemStack
. This is the original compass that was updated using theupdateCompass
method insideManhuntUtilsKt
. - If you return exactly this parameter, not a
copy()
of it, it will cancel the whole update process and ignore the update (even skips other listeners!).
- The oldest
-
newStack
- This is the updated compass
ItemStack
(updated by Manhunt or by another listener), with all the necessary NBT data. - If you return this parameter or a copy of it, the updated compass will remain and will not be modified. Note that it will still be updated by the Manhunt mod, and can be updated by other event listeners.
- This is the updated compass
Return:
The ItemStack
you return from the implementation is the updated compass.
For example, if you use:
CompassUpdateCallback.EVENT.register((oldStack, newStack) -> {
return newStack.setCustomName(new LiteralText("Hello, Events!"));
});
The updated compass will have a custom name of Hello, Events!
if it's not modified by another listener. You can do all kinds of stuff with this callback, like adding enchantments based on the speedrunner location and more cool things.
Speaking of the speedrunner, you can get the speedrunner UUID using ManhuntUtilsKt
, which is also used by the mod internally. I plan to add an actual API that provides all this in the future, but for now you can do:
ManhuntUtilsKt.fromServer(yourMinecraftServerInstance, ManhuntUtilsKt.speedrunner)
to get the speedrunner's PlayerEntity
. Note that you will need to have the instance of MinecraftServer
the mod is running on, which I will not provide.
Documentation coming soon.
Start by registering a CompassUpdateCallback
event in your mod initializer like so:
override fun onInitialize() {
// ... your other code here
CompassUpdateCallback.EVENT.register { oldStack, newStack ->
};
}
Your IDE will probably scream at you at this stage, because you didn't return a value from the lambda. The CompassUpdateCallback
interface requires you to return an ItemStack!
.
For now, you can return newStack
.
Parameter explanation:
-
oldStack
- The oldest
ItemStack!
. This is the original compass that was updated using theupdateCompass
method insideManhuntUtilsKt
. - If you return exactly this parameter, not a
copy()
of it, it will cancel the whole update process and ignore the update (even skips other listeners!).
- The oldest
-
newStack
- This is the updated compass
ItemStack!
(updated by Manhunt or by another listener), with all the necessary NBT data. - If you return this parameter or a copy of it, the updated compass will remain and will not be modified. Note that it will still be updated by the Manhunt mod, and can be updated by other event listeners.
- This is the updated compass
Return:
The ItemStack!
you return from the implementation is the updated compass.
For example, if you use:
CompassUpdateCallback.EVENT.register { oldStack, newStack ->
newStack.setCustomName(LiteralText("Hello, Events!"))
}
The updated compass will have a custom name of Hello, Events!
if it's not modified by another listener. You can do all kinds of stuff with this callback, like adding enchantments based on the speedrunner location and more cool things.
Speaking of the speedrunner, you can get the speedrunner UUID using ManhuntUtils
, which is also used by the mod internally. I plan to add an actual API that provides all this in the future, but for now you can do:
fromServer(yourMinecraftServerInstance, speedrunner)
to get the speedrunner's PlayerEntity?
(you can !!
it if you're certain it exists). Note that you will need to have the instance of MinecraftServer
the mod is running on, which I will not provide.
Documentation coming soon.