Skip to content

Aliases

Martijn Muijsers edited this page Jun 11, 2023 · 7 revisions

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:tuff_stairs, and also a pack called More Stairs that adds more_stairs:tuff_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 tuff_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:tuff_stairs
      to: masonry:tuff_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:tuff_stairs with minecraft:tuff_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:tuff_stairs
      to: minecraft:tuff_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:tuff_stairs is replaced by masonry:tuff_stairs (like in the example above), and the More Stairs pack has a crafting recipe giving more_stairs:tuff_stairs, then that crafting recipe will still be added, but more_stairs:tuff_stairs will be read as masonry:tuff_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:tuff_stairs block, then it is loaded into memory as masonry:tuff_stairs. Later when the chunk is saved again, the block will be saved to the file as masonry_stairs.

Plugins

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

Example

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

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

then the code will work for masonry:tuff_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:tuff_stairs").getKey().toString());

would print "masonry:tuff_stairs".

Clone this wiki locally