-
Notifications
You must be signed in to change notification settings - Fork 2
Adding a plant
This time, we'll be adding slightly more complex behaviours to an entity in order to create a plant that can grow and spread a biome.
We can begin in a similar manner to the last entity, adding the necessary model. This time, however, I'll be adding several models so that the plant can appear to grow (please note that I have used a single material file for all of the models, but you can use a separate one for each):
I can then write the mod file and register the initial empty mod.
ModRegistry.registerMod(new Mod({
name : "New Grass",
version : "1.0.0-beta",
author : "pcr3w",
description : "A basic Equilinox mod to add some new grass to the game.",
init : function() {
// our mod code goes in here
}
});
The code that actually registers the entity will be very similar to that of the Christmas present I made previously, but I have adjusted some things so that it fits as a plant. Of particular note is the array of model files as opposed to the single model file that was used last time.
BlueprintRegistry.registerBlueprint({
// once again, the ID is unique
id : 2512,
// a very boring name, I know
name : "Red Grass",
// I'd recommend that actual descriptions are more informative than this
description : "A brand new type of grass that is bright red!",
// I would like this entity to be classed as a type of grass
classification : "png",
// we'll undercut the normal grass
cost : 50,
// this allows us to have the grass produce around 30DP in-game
dpRate : 30,
// our model data will be very similar to last time
model : {
// I've loaded up all of the models for the different growth stages of the grass
// the order specified here is used for the actual growth order later on
files : ["New Grass 0.obj", "New Grass 1.obj", "New Grass 2.obj", "New Grass 3.obj"],
// the models should have a 1:1 scale in game again
size : 1
},
// the components that we'll add in a bit will be placed in this array
components : []
});
The components array defined above is the important part - components are the things that add new behaviours to entities, such as movement and eating. The component documentation on this wiki is the best place to find all of the information that you will need about the different components.
For adding an entity that is alive, the LifeComponent
is the most important, and is required by many other component types. I have added the bear minimum detail to my life component, but you can read all about additional details that you can fill in.
// this is the component array within the plant blueprint
components : [
// this is the important component for adding life
new LifeComponent({
// the average population size
averagePopulation : 4.4,
// the average life length (in-game hours)
averageLifeLength : 50,
// the number of health points for defending against attacks
defencePoints : 100,
// this entity is a plant, so it is not classified as an animal :P
isAnimal : false,
// the death type of the entity
// this will fade out the entity
death : new FadeDeath(5),
// the breeding properties of the entity
breeding : {
// the plant will be ready for breeding after 15 hours
maturityAge : 15,
// the plant has to wait around 1 hour between each breed
averageBreedTime : 1
}
}),
// this important component allows the plant to appear to grow
// more information can be found under the "Simple Components" section of the wiki
new GrowthComponent({
// the plant should take about 5 hours to grow
time : 5,
// there are four growth stages, as we have four models
stages : 4,
// we want the plant to be static so that the spreader component functions correctly
// each growth stage has one "blocky" sub-stage
subStages : 1
}),
// this small component allows the entity to spread a biome
// more information can be found under the "Simple Components" section of the wiki
new SpreaderComponent({
// the grass will spread the grassland biome
biome : BiomeCodes.GRASSLAND,
// the spreading strength is very strong
strength : 40,
// the biome will be spread within a radius of 10 from the plant
range : 10
})
]
Now that all of the code is written, the game can be loaded up to see if it has worked.
As you can see, the mod worked perfectly and the game now has a (rather OP, admittedly) red species of grass. That is the first living entity that we have added to the game. As you can probably tell, entities end up requiring quite a bit of code, although it is very simple to use.
Now having created an entity that is actually useful in the game, we can progress our way towards creating even more complex entities, such as an animal that moves around and eats.
Next time, we'll be looking very briefly at how the materials of entities can be changed, allowing for parts of variable colour.
Thanks for visiting this wiki. Don't forget to check out Equilinox!
The wiki and the modding framework are still heavily under development, so not all content is available yet.