-
Notifications
You must be signed in to change notification settings - Fork 1
Custom Entry
Links a code-defined CustomLootableEntry to a data-driven Lootable pool/table. These entries can be used when a pre-defined entry type doesn't exist, and creating an entirely new entry type isn't desirable or feasible.
When possible use one of the pre-defined types first; listed in Home
In order for the Lootable pool entry to work, there has to be a corresponding custom entry defined and registered in-code.
The process is simple
- Define a class that implements
CustomLootableEntrywith your desired functionality - Define a
CustomLootableEntryDisplayfor use by the client in creating choice tiles. If you are using your pool only for randomly provided loot, this display can return empty lists and/or description. - Register these classes using
LootablesApi - Link to one or more tables using this pool entry type.
A simple entry implementation that summons a cow at the player's location.
//kotlin
object CowCustomEntry: CustomLootableEntry {
override fun apply(player: ServerPlayerEntity, origin: Vec3d) {
val cow = EntityType.COW.create(player.world)
cow.setPosition(origin.x, origin.y, origin.z)
player.world.spawnEntity(cow)
}
/*
override fun serverDescription(playerEntity: ServerPlayerEntity): Text? {
// If you need server context or entry context to make your description, you can do that here
// otherwise clientDescription in the display should be used
}
*/
}//kotlin
final class CowCustomEntry implements CustomLootableEntry {
public CowCustomEntry{}
@Override
public void apply(ServerPlayerEntity player, Vec3d origin) {
val cow = EntityType.COW.create(player.world);
cow.setPosition(origin.x, origin.y, origin.z);
player.world.spawnEntity(cow);
}
/*
@Override
@Nullable
public Text serverDescription(ServerPlayerEntity playerEntity) {
// If you need server context or entry context to make your description, you can do that here
// otherwise clientDescription in the display should be used
}
*/
}Following from our CowCustomEntry above, the display that would go along with would look like
object CowCustomEntryDisplay: CustomLootableEntryDisplay {
//you probably would have at least one actual TileIcon, but examples of those can be found elsewhere
override fun provideIcons(): List<TileIcon> {
return listOf()
}
//since we don't need any particular server state here, providing the description on the client is better
override fun clientDescription(): Text {
return Text.translatable("my_mod.custom.cow")
}
}final class CowCustomEntryDisplay implements CustomLootableEntryDisplay {
public CowCustomEntryDisplay {}
//you probably would have at least one actual TileIcon, but examples of those can be found elsewhere
@Override
public List<TileIcon> provideIcons() {
return List.of();
}
//since we don't need any particular server state here, providing the description on the client is better
@Override
@Nullable
public Text clientDescription() {
return Text.translatable("my_mod.custom.cow");
}
}Now that we have our entry and display, lets register them. This should be done in Common code, both the server and client need to know at least some of this information.
LootablesApi.registerCustomEntry(Identifier.of("my_mod", "cow_entry"), CowCustomEntry, CowCustomEntryDisplay)LootablesApi.registerCustomEntry(Identifier.of("my_mod", "cow_entry"), new CowCustomEntry(), new CowCustomEntryDisplay());See the JSON definition, Lootable Table, Lootable Pool, and examples below for how to link your new custom entry to a table.
| Key | Type | Value Example | Note |
|---|---|---|---|
"type" |
String |
"lootables:custom" |
|
"id" |
String |
"my_mod:cow_entry" |
Must match to a registered custom entry |
Link your custom entry up to a lootable pool
{
"type": "lootables:custom",
"id": "my_mod:cow_entry"
}