Skip to content

Adding your own gases

Pyrofab edited this page May 11, 2018 · 6 revisions

Basics

Gases have several properties:

  • A type, defining graphical properties such as the item texture or the default particle type
  • A particle type, defining the texture and amount of particles spawned by gas clouds
  • A color, for the particles
  • A bottle color, for the items

Additionally, Gaspunk's default gas implementation has

  • A list of tooltip lines, displayed in the tooltips of items containing those gases
  • A list of gas agents

Gas Agents

By default, gases do not have any specific behaviour besides spawning some particles. The default implementation applies additional effects through gas agents. Those gas agents can act in a number of different ways. As of writing this, there are 3 types of gas agents: damage, potion and sickness.

A damage agent does what it says: it inflicts an amount of damage on the affected entities each tick. Note that this will not kill you instantly thanks to your temporary invulnerability.

A potion agent applies a potion effect with a certain duration and amplifier. The effect will be refreshed every second.

Finally, a sickness agent applies a sickness effect. See the dedicated page for more information.

Gas agents can be defined as toxic or not. Damage agents are obviously always toxic, potion agents use the corresponding attribute in the potion to determine whether they are, and sickness agents define it themselves (technically speaking a sickness may be beneficial). When at least one of a gas' agents is toxic, the gas will slowly empty an entity's air bar. (to emulate entities holding their breath / breathing bad air).

Adding gases through JSON

A very large part of the gas system is data-driven. This means that a lot can be done with a minimal amount of programming. This part can be done by modders and modpack makers alike.

Adding Gas Agents

JSON files describing custom gas agents go in their own folder. If you are coding an add-on, create a gaspunk_agents directory in your mod's assets (assets/modid/gaspunk_agents). If you are creating a modpack, use the custom_agents directory in gaspunk's config (config/gaspunk/custom_agents). In both cases, the mod will detect those directories and load any JSON file it contains.

To choose the type of your gas agent, use the factory property. This field is always required and can be any of the existing types. A gas agent requires different properties to be set in accordance with the chosen type. Damage agents require the maxDamage (amount inflicted when the concentration of gas breathed is 100%), potion agents require the potion id, the duration and the amplifier and sickness agents require the sickness id, whether it ignoreBreath (if false, it will wait until the entity has ran out of air before afflicting it with the sickness) and whether it is toxic or not. For examples, you can check out Gaspunk's built-in agents here.

Adding Gases

Now that you know how to make your own agents, it it time to learn how to make your own gases. Note that Gaspunk's default agents can be reused anyway, so you can do this part without your own agents. JSON files for gases are loaded in much the same way as those for gas agents, with the directories being respectively gaspunk_gases and custom_gases. The created gas' id will be the name of the file, so try not putting anything too exotic in there.

Most properties are optional, with only the gas type being mandatory. Those are as follow (see above for descriptions):

Property name Valid values Default
gasType GAS, SMOKE
particleType GAS, SMOKE, CANDYFLOSS gasType's default particle type
color any hexadecimal color using the format 0xAARRGGBB 0x00000000 (invisible)
bottleColor any hexadecimal color using the format 0xAARRGGBB color
tooltipLines a list of string, one entry per tooltip line no tooltip
agents a list of agents, each entry containing the name and potency of the agent no agent

For examples, you can check out Gaspunk's built-in gases here.

Adding Gas Recipes

Gaspunk offers a way to do gas brewing recipes through JSON files. Files describing such recipes should be put either in a mod's gaspunk_recipes folder or in gaspunk's config custom_recipes. The format should be quite familiar to modders as it is very similar to forge's (and by extension minecraft's) for crafting recipes. There are 3 required fields:

  • result, the id of a gas. The result of the brewing recipe will be a gas tube containing that gas.
  • input, the base for the recipe (put in the bottle slots of the brewing stand)
  • ingredient the ingredient for the recipe (put in the top slot of the brewing stand) input and ingredient can be any valid ingredient as defined by forge. Most of the time it will be an item or a forge dictionary entry, which are defined as such:
  "ingredient/input": {
    "type": "minecraft:item",
    "item": "..."
  }

or

  "ingredient/input": {
    "type": "forge:ore_dict",
    "ore": "..."
  }

input can also accepts a tube containing a specific gas when given its id, like so:

  "input": {
    "gas": "..."
  }

See the built-in recipes for concrete examples.

Adding gases through code

This part is only available to modders for obvious reasons.

Gases have their own registry. As such, you can register new gases using the appropriate registry event, like so:

public void addGases(RegistryEvent.Register<IGas> event) {
  event.register(AbstractGas.builder()
    .setType(GasTypes.SMOKE)
    .setColor(0xFFF4C242)
    .build()
    .setRegistryName(YourMod.MOD_ID, "my_smoke")
  );
}

The code above will register a new colored smoke, which is the most basic gas you can make. It will automatically add the corresponding tube and grenade to gaspunk's creative tab as well. There are however several ways of adding custom behaviour for your gas. The first one is to create your own IGasAgent and pass it to the builder. The second one is to make your own implementation of IGas.

The most useful method to override would be applyEffect. This method is called every tick when an entity is breathing your gas. Most parameters should be fairly explicit, though you may be wondering what concentration is. Gas clouds actually compute the clear path distance in blocks between the emission point and the affected entities. That concentration is the computed distance divided by the maximum gas propagation distance.