Temporal API - Library for Minecraft Mod Developers
Temporal API is an official library created by the Temporal team for their projects. This library is open for use by other developers, mod creators, and modpack creators in their own projects without restrictions.
Main Features
The main goal of this mod is to significantly simplify and make the process of creating Minecraft mods more flexible. The library provides many useful tools and utilities that save developers time.
Getting Started
To connect the library to your project, you need to add the following lines to the build.gradle file:
repositories {
maven {
url "https://cursemaven.com"
}
}
dependencies {
implementation fg.deobf("curse.maven:temporalapi-970291:<file-id>")
...
}
Replace <file-id> with the appropriate identifier that can be found at the end of the link to the required mod file version.
Main Library Components
Factories and Extensions
Factories are used to create RegistryObject objects, significantly simplifying this process. Here's an example of creating an item factory facade:
public class ModItemFactoryFacade extends ItemFactory {
public ModItemFactoryFacade() {
super(ModItems.ITEMS);
}
}
You can extend your factory facade with extensions from the API or create your own extensions. For example, using SwordExtension makes creating swords much easier:
public class ModItemFactoryFacade extends ItemFactory implements SwordExtension {
public ModItemFactoryFacade() {
super(ModItems.ITEMS);
}
}
Or a more advanced version:
public class ModItemFactoryFacade extends ItemFactory implements SwordExtension {
public ModItemFactoryFacade() {
super(ModItems.ITEMS);
}
public RegistryObject<SwordItem> createSword(String name, Object... args) {
return SwordExtension.super.createSword(name, this, args);
}
public RegistryObject<? extends SwordItem> createSword(String name, Supplier<? extends SwordItem> tTypedSupplier) {
return SwordExtension.super.createSword(name, this, tTypedSupplier);
}
}
Factory Usage Example
public class ModItems {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(Registries.ITEM, "MOD_ID");
public static final ModItemFactoryFacade ITEM_FACTORY = new ModItemFactoryFacade();
public static final RegistryObject<Item> MY_ITEM_1 = ITEM_FACTORY.create("my_item_1");
public static final RegistryObject<Item> MY_ITEM_2 = ITEM_FACTORY.create("my_item_2", new Item.Properties());
public static final RegistryObject<Item> MY_ITEM_3 = ITEM_FACTORY.create("my_item_3", () -> new Item(new Item.Properties()));
// First example of creating objects through facade
public static final RegistryObject<SwordItem> MY_SWORD_1 = ITEM_FACTORY.createSword("my_sword_1", ITEM_FACTORY, Tiers.STONE, 3, -2.4F);
public static final RegistryObject<? extends SwordItem> MY_SWORD_2 = ITEM_FACTORY.createSword("my_sword_2", ITEM_FACTORY, () -> new SwordItem(Tiers.STONE, 3, -2.4F, new Item.Properties()));
// Second example of creating objects through facade
public static final RegistryObject<SwordItem> MY_SWORD_3 = ITEM_FACTORY.createSword("my_sword_3", Tiers.STONE, 3, -2.4F);
public static final RegistryObject<? extends SwordItem> MY_SWORD_4 = ITEM_FACTORY.createSword("my_sword_4", () -> new SwordItem(Tiers.STONE, 3, -2.4F, new Item.Properties()));
}
The args... array represents arguments for creating an object (readability will be improved in the future).
Available Factories and Extensions
ItemFactory (ArrowExtension, BowExtension, BowlExtension, MusicDiscExtension, SmithingTemplateExtension, SwordExtension, AxeExtension, PickaxeExtension, ShovelExtension, HoeExtension)
BlockFactory (BushExtension, FlowerExtension, PottedFlowerExtension)
ParticleFactory
EffectFactory
PaintingFactory
PotionFactory
SoundEventFactory
CreativeTabFactory
EntityFactory
Tag Utilities
Tag utilities focus on creating tags and simplifying work with them. For example, to create an item tag, use ItemTagFactory:
public class MyItemTags {
public static final TagFactory<Item> TAG_FACTORY = new ItemTagFactory("MY_MOD_ID");
public static final TagKey<Item> MY_TAG = TAG_FACTORY.createTag("my_tag");
}
Creative Tab Utilities
Creative tab utilities are used to add items to the required creative tabs. Usage example:
@SubscribeEvent
public void addCreativeTabs(BuildCreativeModeTabContentsEvent event) {
new SimpleTabAdder(event)
.addAllToTab(CreativeModeTabs.INGREDIENTS, ModItems.MY_ITEM_1, ModItems.MY_ITEM_2, ModItems.MY_ITEM_3)
.addAllToTab(CreativeModeTabs.COMBAT, ModItems.MY_SWORD_1, ModItems.MY_SWORD_2, ModItems.MY_SWORD_3);
}
Trading Utilities
TemporalAPI significantly simplifies setting up trading with villagers and wanderers:
public static final TradeCustomizer tradeCustomizer = new SimpleTradeCustomizer();
@SubscribeEvent
public void customizeTradesWithVillagers(VillagerTradesEvent event) {
tradeCustomizer.customize(event, new VillagerTrade(
new TradingItemHolder(Items.ANDESITE, 2),
new TradingItemHolder(Items.EMERALD, 3),
new VillagerTradeDescription(
VillagerProfession.ARMORER, 1, 5, 5, 0.5f
)
));
}
@SubscribeEvent
public void customizeTradesWithWanderers(WandererTradesEvent event) {
tradeCustomizer.customize(event, new WandererTrade(
new TradingItemHolder(Items.ANDESITE, 2),
new TradingItemHolder(Items.EMERALD, 3),
new WandererTradeDescription(
WandererTradeDescription.TradeRarity.RARE, 5, 5, 0.5f
)
));
}
Item Properties Utilities
Adding necessary properties for bows, shields, and other items:
@SubscribeEvent
public void clientSetup(final FMLClientSetupEvent event) {
event.enqueueWork(() -> {
TemporalItemProperties.makeBow(ModItems.MY_BOW_1);
TemporalItemProperties.makeShield(ModItems.MY_SHIELD_1);
TemporalItemProperties.makeCrossbow(ModItems.MY_CROSSBOW_1);
TemporalItemProperties.putCompostable(ModBlocks.MY_FLOWER_1, 4);
});
}
Frequently Asked Questions
Will there be a Fabric version? No, a Fabric version is not planned.
Can I use this mod in my modpacks? Yes, you can freely use this mod in any modpacks!
How to suggest features or report bugs? Join our Discord for any comments, questions, suggestions, or problems!