Skip to content

Aliases

Martijn Muijsers edited this page Feb 21, 2024 · 7 revisions

    🧱    Aliases have been designed and are being worked on,    
             but they have not been finished and added yet.    
 

Sometimes, there may be multiple packs that add the same block or item. This currently happens frequently with mods: there are a lot of mods that add their own copper to Feed The Beast.

For example, there may be a pack called Masonry that adds masonry:calcite_stairs, and also a pack called More Stairs that adds more_stairs:calcite_stairs. Similarly for items, there may be a pack called All The Nuggets that adds all_the_nuggets:copper_nugget, and also a pack called Metal Constructions that adds metal_construction:copper_nugget.

In this case, it's not nice to have multiple versions of the same item. To avoid having multiple versions of the same item, while still making it possible for server owners to use both these packs if they want, Fiddle allows servers to define that some block/item keys from one pack are aliases for another.

Configuring aliases

In the global configuration (config/fiddle-global.yml) there is a setting aliases > global > materials, which initially is empty:

aliases:
  global:
    materials: []

Here is an example where 1 duplicate key of calcite_stairs and 2 duplicate keys of copper_nugget (one of which is called copper_shard in its pack) are replaced:

aliases:
  global:
    materials:
    - from:
      - more_stairs:calcite_stairs
      to: masonry:calcite_stairs
    - from:
      - all_the_nuggets:copper_nugget
      - copper_craziness:copper_shard
      to: metal_construction:copper_nugget

to is the key that is used for the block/item on the server.
from is a list of keys that are just aliases: they are replaced with the to key.

Here is another example that replaces more_stairs:calcite_stairs with minecraft:calcite_stairs. You can define such an alias if you are using or previously used a pack that adds a block that was later added into the vanilla game in an update:

aliases:
  global:
    materials:
    - from:
      - more_stairs:calcite_stairs
      to: minecraft:calcite_stairs

Effects

Packs

All occurrences of an aliased block/item key (in a from) get replaced by the one configured as to.

For example, if more_stairs:calcite_stairs is replaced by masonry:calcite_stairs (like in the example above), and the More Stairs pack has a crafting recipe giving more_stairs:calcite_stairs, then that crafting recipe will still be added, but more_stairs:calcite_stairs will be read as masonry:calcite_stairs instead.

World data

When world data is loaded into memory, all occurrences of an aliased block/item key (in a from) get replaced by the one configured as to.

For example, when a chunk file contains a more_stairs:calcite_stairs block, then it is loaded into memory as masonry:calcite_stairs. Later when the chunk is saved again, the block will be saved to the file as masonry_stairs.

Plugins

All plugins that use direct comparisons on Material will work as normal.

Example

If more_stairs:calcite_stairs is replaced by masonry:calcite_stairs, and you write the following code:

@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    if (event.getBlock().getType() == Material.matchMaterial("more_stairs:calcite_stairs")) {
        event.getPlayer().sendMessage("So you think you are calcite?");
    }
}

then the code will work for masonry:calcite_stairs blocks too.

How it works

For any block/item key that has been replaced, Material.matchMaterial(<namespaced key>) will return the Material configured as to.

So, for the example above, this:

System.out.println(Material.matchMaterial("more_stairs:calcite_stairs").getKey().toString());

would print "masonry:calcite_stairs".

Clone this wiki locally