Skip to content

Fire Components

Crystal Spider edited this page Jul 20, 2024 · 3 revisions

Use

Fire Components are essential to work with Fire related objects, such as blocks and items.
Each Fire Component is mapped to a specific registry and stores a ResourceLocation that identifies the related object.

  • Fire.Component#SOURCE_BLOCK: References the fire source block.

  • Fire.Component#CAMPFIRE_BLOCK: References the campfire block.

  • Fire.Component#CAMPFIRE_ITEM: References the campfire item, should be used together with the campfire block.

  • Fire.Component#LANTERN_BLOCK: References the lantern block.

  • Fire.Component#LANTERN_ITEM: References the lantern item, should be used together with the campfire block.

  • Fire.Component#TORCH_BLOCK: References the torch block, standing on the ground version.

  • Fire.Component#WALL_TORCH_BLOCK: References the wall torch block, attached to a wall version.

  • Fire.Component#TORCH_ITEM: References the torch item, should be used together with the torch block.

  • Fire.Component#FLAME_PARTICLE: References the flame particle, should be used at least with the torch block.

Before 1.21

Before Minecraft 1.21, data driven enchantments weren't a thing, so there were two more Fire Components:

  • Fire.Component#FIRE_ASPECT_ENCHANTMENT: References the custom Fire Aspect enchantment.

  • Fire.Component#FLAME_ENCHANTMENT: References the custom Flame enchantment.

Registration

Registering Fire Components is essential for the API to work properly.
Fire Components are registered when building a Fire.
If you don't need a specific Fire Component, you have to explicitly remove it from the Fire, otherwise it will be set with a default value.
Generally, changing the value from the default is not suggested, unless you are removing them or cannot do otherwise (such as when registering for another mod).

Removing a Fire Component is as easy as:

// Replace SOURCE_BLOCK with the Fire Component you want to remove.
FireManager.fireBuilder(CUSTOM_FIRE_TYPE).removeComponent(Fire.Component.SOURCE_BLOCK);

Changing the value of a Fire Component from default is as easy as:

// Replace SOURCE_BLOCK with the Fire Component you want to change.
FireManager.fireBuilder(CUSTOM_FIRE_TYPE).setComponent(Fire.Component.SOURCE_BLOCK, new ResourceLocation(MOD_ID, "custom_value"));

The list below also includes registration for the related game object referenced by the Fire Component.
If you register such objects with Soul Fire'd API as described below, you must not change the default value of the associated Fire Component.

For each registration method, there is at least one overload that allows for greater customizability for the game object, but this guide focuses on the simplest overloads instead.
When you register game objects, remember to add the required assets and data.

Beware that now the order in which you register stuff is very important.
Each items requires the related block, so you must register the block before the item.
The torch blocks require the flame particle, so you must register the particle before the torch blocks.
The fire itself must be registered before each of the other components.
That's all, but it's mandatory to respect these rules.

SOURCE_BLOCK
/**
 * Create the Block Tag reference for your base blocks.
 */
public static final TagKey<Block> CUSTOM_FIRE_BASE_BLOCKS = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "custom_fire_base_blocks"));

/**
 * Register your fire source block, the actual fire block in-game.
 * Choose a block tag, which can also be custom, that will serve as your fire base block: when a block of that kind is set on fire, your fire will be used instead of the normal one.
 * 
 * Note that MapColor is called MaterialColor before 1.19.4
 */
  public static final Supplier<CustomFireBlock> CUSTOM_FIRE_SOURCE = FireManager.registerFireSource(CUSTOM_FIRE_TYPE, CUSTOM_FIRE_BASE_BLOCKS, MapColor.COLOR_PURPLE);

CustomFireBlock is a class provided by Soul Fire'd API to easily create fire blocks that integrate with the API.
If you want to customize it, you should subclass it.

CAMPFIRE_BLOCK
/**
 * Register your campfire block.
 * The boolean determines whether it should spawn ember particles.
 */
public static final Supplier<CustomCampfireBlock> CUSTOM_CAMPFIRE = FireManager.registerCampfire(CUSTOM_FIRE_TYPE, false);

CustomCampfireBlock is a class provided by Soul Fire'd API to easily create campfire blocks that integrate with the API.
If you want to customize it, you should subclass it.

When customizing campfires there are a few things to know to do it properly.
Vanilla campfires a Block Entity to handle their inventory and behavior.
CustomCampfireBlocks are no different, but they don't use the same Vanilla Block Entity. This is because Vanilla Block Entities can tick only on a specific set of blocks, so when creating new blocks there is a need to create new Block Entities.
Luckily, Soul Fire'd API provides a DynamicBlockEntityType to register custom Block Entities that can be applied to a dyanmic list of blocks.
By default, campfires registered with the API will already have a ticking Block Entity for them, but you might want to customize the ticking behavior.

To fully customize any campfire behavior, first create two classes, let's call them MyCampfireBlock and MyCampfireBlockEntity, which subclass CustomCampfireBlockEntity and CustomCampfireBlock.

Customizing a campfire block mostly means customizing the ticking Block Entity behaviors.
Inside MyCampfireBlockEntity, override the method getType() to return a new Block Entity Type you'll need to register as follows:

public static final Supplier<DynamicBlockEntityType<MyCampfireBlockEntity>> MY_CAMPFIRE_ENTITY_TYPE = CobwebRegistry.of(Registries.BLOCK_ENTITY_TYPE, MOD_ID).register(
  // Use the same name as the campfire, which defaults to Fire Id + "_campfire"
  "custom_campfire",
  () -> new DynamicBlockEntityType<>(MyCampfireBlockEntity::new)
);

And in your MyCampfireBlock class override the following methods:

// In your MyCampfireBlock class...

/**
 * Override to return your MyCampfireBlockEntity instance.
 */
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
  return new MyCampfireBlockEntity(pos, state);
}

/**
 * Override to return your MY_CAMPFIRE_ENTITY_TYPE.
 */
@Override
protected DynamicBlockEntityType<CustomCampfireBlockEntity> getBlockEntityType() {
  return MY_CAMPFIRE_ENTITY_TYPE.get();
}

Then, you can override any method you want in either classes to customize your behavior.

However, there are three static methods from the Block Entity that need further care to be customized properly.
Since they are static, they cannot be overridden, and you instead need to create new static methods in your MyCampfireBlockEntity.
Once that's done, to make the campfire actually use them you need to override the following methods:

// In your MyCampfireBlock class...

/**
 * Return the particleTick override for the custom campfire block entity.
 */
@Override
protected BlockEntityTicker<CampfireBlockEntity> particleTick() {
  return MyCampfireBlockEntity::customParticleTick;
}

/**
 * Return the cookTick override for the custom campfire block entity.
 */
@Override
protected BlockEntityTicker<CampfireBlockEntity> cookTick() {
  return MyCampfireBlockEntity::customCookTick;
}

/**
 * Return the cooldownTick override for the custom campfire block entity.
 */
@Override
protected BlockEntityTicker<CampfireBlockEntity> cooldownTick() {
  return MyCampfireBlockEntity::customCooldownTick;
}
CAMPFIRE_ITEM
/**
 * Register your campfire item.
 */
public static final Supplier<BlockItem> CUSTOM_CAMPFIRE_ITEM = FireManager.registerCampfireItem(CUSTOM_FIRE_TYPE);
LANTERN_BLOCK
/**
 * Register your lantern block.
 */
public static final Supplier<CustomLanternBlock> CUSTOM_LANTERN = FireManager.registerLantern(CUSTOM_FIRE_TYPE);

CustomLanternBlock is a class provided by Soul Fire'd API to easily create lantern blocks that integrate with the API.
If you want to customize it, you should subclass it.

LANTERN_ITEM
/**
 * Register your lantern item.
 */
public static final Supplier<BlockItem> CUSTOM_LANTERN_ITEM = FireManager.registerLanternItem(CUSTOM_FIRE_TYPE);
TORCH_BLOCK and WALL_TORCH_BLOCK
/**
 * Register both your torch and wall torch blocks.
 */
public static final Pair<Supplier<CustomTorchBlock>, Supplier<CustomWallTorchBlock>> CUSTOM_TORCH = FireManager.registerTorch(CUSTOM_FIRE_TYPE);

CustomTorchBlock and CustomWallTorchBlock are classes provided by Soul Fire'd API to easily create torch blocks that integrate with the API.
If you want to customize them, you should subclass them.

TORCH_ITEM
/**
 * Register your torch item.
 */
public static final Supplier<StandingAndWallBlockItem> CUSTOM_TORCH_ITEM = FireManager.registerTorchItem(CUSTOM_FIRE_TYPE);
FLAME_PARTICLE
/**
 * Register your flame particle.
 */
public static final Supplier<SimpleParticleType> CUSTOM_FIRE_FLAME = FireManager.registerParticle(CUSTOM_FIRE_TYPE);