Bees with KubeJS

Currently, it is only possible to add a bee species using KubeJS. Data packs and CraftTweaker are not supported.

Forestry bees are not data-driven, so new species cannot be added using datapacks. Instead, I have provided KubeJS support so that you may still add new bee species without needing to create a whole addon mod.

There are a number of reasons for why bees are not yet data-driven: * Difficult for me to code, as I was unfamiliar with Forestry's API before porting it * Massive changes in 1.20.4 and 1.21 would require me to rewrite it several times * Most interesting bee species cannot be implemented in JSON alone (ex. custom bee effects) * Most people already use KubeJS or CraftTweaker instead of writing datapacks by hand

There are a few disadvantages: * Cannot reload bee species with /reload or rejoining a world * Currently there is no CraftTweaker support, so modpack makers are forced to use KubeJS

And there are also a few advantages: * Easier to maintain because Forestry is less reliant on Minecraft's constantly changing systems * Forestry's API is the same for mod authors and modpack developers, which makes it easier to learn making an addon mod * Modpack makers must learn a real-world programming language (JavaScript) instead of ZenScript * Those using ProbeJS will be working with types instead of JSON schemas.

I might add CraftTweaker support if enough people ask for or donate for it, or if someone submits a pull request. In the meantime, bees won't be data-driven until Minecraft's code starts to stabilize. Enough of that, let's make a bee species.


Registering a species

Registering a bee species is done using ApicultureEvent.registerSpecies. First, let's see the function signature:

public IBeeSpeciesBuilder registerSpecies(ResourceLocation id, String genus, String species, boolean dominant, Color outline);

From that, we can see that a species needs...

  1. a unique ID - used in NBT and translation keys.
  2. a genus - see the Genera with KubeJs page for more info.
  3. a scientific species name
  4. a true/false value indicating whether this species is dominant or recessive
  5. an outline color

The genus determines which genus/line of bees this species belongs to, and . The species is used in the 5th page of the Analyzer, the dominant boolean is used in inheritance, and the outline color should be self-explanatory.

Let's see this in action:

// startup_scripts/my_first_bee.js

ForestryEvents.apiculture(apiculture => {
  apiculture.registerSpecies('custom:nethertine', ForestryTaxa.GENUS_INFERNAL, 'stellaris', true, Color.of('#DC143C'))
})

Here, we're registering a new bee species with ID custom:nethertine that belongs to the Infernal genus, whose scientific name is Diapis stellaris, whose species allele is dominant, and whose outline color is #DC143C, which is a slightly pinkish red. If we go in game, we'll see this:

Picture of Analyzer

Since we specified this bee's genus as the Infernal genus, it inherits all the alleles defined by that genus. You can see all the default genera and their alleles here.

We'll need a resource pack to add an English translation for the species name. Look at the official KubeJS docs to figure out how to do that. If you want an Encyclopedia Minecraftia entry, then you'll need another entry in the language file. Both translation keys are derived from the species's ID.

Here's what my assets/custom/lang/en_us.json language file would look like:

{
  "allele.forestry.bee_species.custom.nethertine": "Nethertine",
  "allele.forestry.bee_species.custom.nethertine.desc": "\"Brilliant light shone through the endless hells. Its dazzling colors burned into my soul...\"|TheDarkColour, Bee Historian"
}

Customizing the bee species

If you look back at the function definition for registerSpecies, you'll notice that it returns an IBeeSpeciesBuilder. You can see all of its methods in the source code on Github.

Here's a summary of what you can do:

  • Products: Use addProduct to add regular drops to this bee.
  • Specialties: Use addSpecialty to add specialty drops only produced when the bee is jubilant (usually, exact climate preference)
  • Body color: Change the bee's yellow body color to something else using setBody
  • Stripe color: Change the bee's black stripes color to something else using setStripes
  • Jubilance: Change the bee's jubilance conditions from something other than being in its preferred climate.

IBeeSpeciesBuilder is also a type of ISpeciesBuilder. See its methods here. This means you can also change these properties:

  • Genome: Use setGenome to customize the default alleles of the bee. See all alleles here.
  • Glint: Use setGlint to add an enchantment glint to the bee's item forms.
  • Climate: Use setTemperature and setHumidity to set the bee's preferred temperature and humidity, respectively.
  • Authority: Use setAuthority to change "Authority" in the 5th tab of the analyzer. Default is Sengir.
  • Complexity: Use setComplexity with a number between 1 and 10 to change how many cells appear for this species in the Escritoire minigame.
  • Secret: Use setSecret(true) to indicate that this species is a secret species that can't be discovered in the Escritoire. In base Forestry, only Holiday bees are secret.

Here's an example of how I decided to customize my Nethertine species:

// startup_scripts/my_first_bee.js

ForestryEvents.apiculture(apiculture => {
  apiculture.registerSpecies('custom:nethertine', 'diapis', 'stellaris', true, Color.of('#DC143C'))
    .addSpecialty(Items.NETHER_STAR, 0.05)
    .setGenome(genome => {
      genome.set(BeeChromosomes.LIFESPAN, ForestryAlleles.LIFESPAN_ELONGATED)
    })
    .setBody(Color.of('#000000'))
    .setAuthority('TheDarkColour')
    .setGlint(true)
})

I hit most of the important properties here. To change the default alleles, you use setGenome, which accepts a function to set alleles. The set function accepts a chromosome and an allele for that chromosome. See all of the bee chromosomes in BeeChromosomes, and all of the alleles in ForestryAlleles.