This document outlines best-practices and contributing guidelines to VampireLib.
By contributing to VampireLib you agree with the Developer Certificate of Origin (DCO).
Trivial fixes that do not require review (e.g. typos) are exempt from this policy. VampireLib team members should double check with other members of the team on Discord before pushing a commit or merging a PR without going through this process.
PRs that do not fit under any of these categories but are not "trivial fixes" are merged at the consensus of the VampireLib team, using whatever criteria they determine to be appropriate.
This is only a summary of VampireLib's PR process and an explanation of VampireLib-specific exceptions to it. For exact definitions and more information, see RFC 39.
Use UpperCamelCase
for class names.
Use lowerCamelCase
for method names, variable names, and names of fields that are not both static and final.
Use UPPER_SNAKE_CASE
for names of fields that are both static and final, excluding atomics like AtomicInteger
, AtomicBoolean
or AtomicReference
.
Method names should generally be verb phrases (tick
, getCarversForStep
), except for "withX", "toX", "fromX", "of"
and builder methods.
Class names and non-boolean field and variable names should be noun phrases (ChunkRegion
, color
).
Boolean field and variable names should always be adjective phrases or present tense verb phrases (powered
, canOpen
), avoiding the is
and has
prefixes when possible (colored
, not isColored
or hasColor
).
To make code as easy to read as possible, keep names in the natural language order. For example, a class representing a
chest block entity should be named ChestBlockEntity
rather than BlockEntityChest
. Though prefix naming may be
helpful for grouping classes together in an IDE's tree view, reading and writing code is done much more often than
browsing files.
Use American English for consistency throughout VampireLib.
If there are two acceptable spellings of the same word, first check if one is already being used in VampireLib, Quilt Mappings or by Mojang, and if not, use the most common spelling.
Omit words that are made redundant by parameter names or owner class names. For example, use getChunk(BlockPos pos)
rather than getChunkAtPosition(BlockPos pos)
and Box.create
rather than Box.createBox
. Don't avoid overloading
methods or shadowing fields.
However, it's more important for a name to be descriptive rather than short, so don't omit important words. When naming something always look at all its usages, including overriding methods and inheriting classes.
It's important to be concise especially with names used in many places throughout the code, while more obscure names can be longer and more descriptive.
Avoid abbreviations unless it's a common one everyone knows and other Quilt Mappings names involving the same word use its abbreviated form. Full names are easier to read quickly and remember ("Which words were abbreviated?") and they often don't take more time to type thanks to IDE autocompletion. Common abbreviations you should use are:
- "id" for "identifier"
- "pos" for "position"
- "nbt" for "named binary tag"
- "init" for "initialize"
- "min"/"max" for "minimum"/"maximum"
- Any abbreviations used by Java or libraries ("json", "html", etc.)
- "o" for the parameter of
equals(Ljava/lang/Object;)Z
methods - "prev" for "previous"
Treat acronyms as single words rather than capitalizing every letter. This improves readability (compare JsonObject
and
JSONObject
) and it's consistent with Mojang naming (a known name is NbtIo
).
Abbreviations you shouldn't use are:
- "loc" for "location"
Please avoid the use of abbreviations in javadocs, except if those describe the name of a format, a library, etc.
Consistency is important as it makes code more readable and names easier to memorize. When possible, use terms that are present in VampireLib, in other Quilt Mappings names, in libraries used by Minecraft, or in vanilla strings. The rest of this section lists common names and name patterns you should use.
Use "tick" for updates done once per tick. Use "update" for other kind of updates.
Use the word "last" for the value that something had last tick (lastX
, lastWidth
, etc.).
Use "get" for non-boolean getters and other methods that calculate some property with no side effects other than caching a value in a private field. For boolean getters, use "is".
Use "set" for methods that set some property. Name the parameter the same as the property (setColor(color)
, not
setColor(newColor)
).
Use "with" for methods that return a copy of an object with a different value for some property. Name the parameter the same as the property.
Use "create" for methods that create a new instance of some object. Use "get or create" for methods that create a new instance only if one does not already exist. Don't use "get or create" for lazy initialization, though.
Use "serializer" for objects whose purpose is serializing or deserializing some type of object (RecipeSerializer
).
Use "serialize" and "deserialize" for methods only when serializing or deserializing an object other than the one the
method is in.
Use "from" for static methods that create an object of the method owner's type (fromJson
, fromNbt
, fromString
).
Use "to" for methods that convert an object to another type (toString
, toLong
, toNbt
).
Use "read" for non-static methods that load data into the object. Use "write" for methods that save data to an * existing* object passed as a parameter.
Use "factory" for objects whose purpose is creating other objects.
Use "builder" for objects whose purpose is helping with the creation of an immutable object. Name builder methods the same as the field they're setting, without any prefix.
Use a plural name for collections and maps rather than the words "list", "set", "array", etc., unless it's a collection
of collections or there are several collections of different types containing the same objects (entities
, entityLists
).
When it's enough, name maps based on the value type. Otherwise, name it in the "valuesByKeys
" format.
Coordinates can be named x
, y
, and z
when it's clear what they represent. If clarification is needed, add a word
in front of the coordinate (velocityX
, not xVelocity
).
Name screen coordinates x
and y
, rather than left
and top
.
Write sentences for class, method and field javadocs, starting with an uppercase and ending with a period. Start method
docs with verbs, like Gets
or Called
. Use HTML tags such as <p>
between paragraphs if the docs have several, as
line wraps are converted to spaces in the generated documentation. Feel free to start a new line whenever you feel the
current line is too long.
Parameter and @return
documentation should use quick descriptions without initial capitalization or punctuation, such
as {@code true} if the block placement was successful, {@code false} otherwise
.
{@return}
used in the first sentence can duplicate enclosed text to the return description.
Use {@index}
to allow enclosed text to be indexed by the Javadoc search.
Javadoc will take the first sentence, ended by the first .
, as a brief description of the member you are documenting.
Note that .
from abbreviations, such as i.e.
, count.
The $
character may be used in mixins to mark a semantic separation in the name, in other words it allows to separate
the actual name of the variable and the namespace.
@Unique
fields must be prefixed with vl$
, but @Unique
methods don't need prefixes.
In the case of a pseudo-local variable (a field used briefly to pass around a local variable of a method between 2
injections of said method), the field should be named with the namespace first, then the name of the injected method,
and finally the name of the local (vl$injectedMethod$localName
).
VampireLib is licensed under Apache 2.0, and have a Developer Certificate of Origin (DCO) which you need to agree with to contribute. Commit author may be sufficient, but a sign-off can be added too, and legal names are not required for privacy reasons.
Every Java source file in VampireLib has a license header with a copyright notice that keeps track of its creation date and last modification date.
Two gradle tasks are dedicated to them:
:checkLicenses
will check the presence and validity of the license header in each Java source file;:applyLicenses
will automatically apply the correct license header to every Java source file; it can be used to add missing headers and update copyright dates across the whole code base.
So, before committing, remember to run :applyLicenses
!
Please refer to the DCO.
If your work comes from Fabric API, then you should put /// FABRIC
at the beginning of your file,
and if your work comes from QSL, then you should put /// QUILT
instead of /// FABRIC
, or in the case
you're copying an entire file in it, you can just keep the same header without modification.
Make sure to execute the :applyLicenses
task as it will apply a special license header to Fabric API or QSL-derived files
mentioning Fabric's or Quilt's copyright notice.
Files derived from Fabric or Quilt must use this license header!