Bugs and Banners (and a Rest)

Sometimes you need to slow down and focus on other things, and this week has been particularly hectic. So, I didn’t get as much done this week as I usually do. I still fixed a couple of bugs and added a new feature. I’m hoping that within the next couple of weeks I’ll have the Villager release finished.

Butterfly Banner Pattern


To flesh out the butterfly mod, I wanted to add a new banner pattern that would represent the butterfly mod. These banners could also be used in structures to add a bit of flavour to the lepidopterist’s home.

Adding a new banner pattern is fairly simple. You start with a registry, as always, except in this case we don’t expose the registry objects themselves. You need to have a TagKey that references the banner pattern, which is then used to register the banner pattern item. I create this key in the registry’s initialise method and provide an accessor for the item registry to use.

/**
 * Registers and gives access to banner patterns.
 */
public class BannerPatternRegistry {

    // An instance of a deferred registry we use to register items.
    private final DeferredRegister<BannerPattern> deferredRegister;

    // The banner pattern tags.
    private TagKey<BannerPattern> butterflyBannerPatternTagKey;

    /**
     * Construction
     * @param modEventBus The event bus to register with.
     */
    public BannerPatternRegistry(IEventBus modEventBus) {
        this.deferredRegister = DeferredRegister.create(Registries.BANNER_PATTERN, ButterfliesMod.MOD_ID);
        this.deferredRegister.register(modEventBus);
    }

    /**
     * Register the banner patterns.
     */
    public void initialise() {
        // Register the banner pattern itself.
        deferredRegister.register("banner_pattern_butterfly", () -> new BannerPattern("banner_pattern_butterfly"));

        // Register the tag used to link everything together.
        this.butterflyBannerPatternTagKey = TagKey.create(
                Registries.BANNER_PATTERN,
                new ResourceLocation(ButterfliesMod.MOD_ID, "banner_pattern_butterfly"));
    }

    /**
     * Accessor to the butterfly banner pattern tag key.
     * @return The tag key.
     */
    public TagKey<BannerPattern> getButterflyBannerPatternTagKey() {
        return butterflyBannerPatternTagKey;
    }
}

For the item itself we can use a BannerPatternItem to create it. This will need all of the usual item models, textures and so on when we add a new item.

        this.butterflyBannerPattern = deferredRegister.register("banner_pattern_butterfly", () -> new BannerPatternItem(
                bannerPatternRegistry.getButterflyBannerPatternTagKey(),
                (new Item.Properties()).stacksTo(1).rarity(Rarity.UNCOMMON)));

The pattern itself needs two textures: one for a banner, and the other for shields. I based these off the textures you will find in vanilla, as they have slightly different sizes when they are rendered.

The banner pattern needs 18 total localisation strings. One for the item itself, one item description that is used for subtext, and 1 for each of the 16 main colours used when they are added to a banner.

  "block.minecraft.banner.butterflies.banner_pattern_butterfly.black": "Black Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.blue": "Blue Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.brown": "Brown Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.cyan": "Cyan Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.gray": "Gray Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.green": "Green Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.light_blue": "Light Blue Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.light_gray": "Light Gray Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.lime": "Lime Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.magenta": "Magenta Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.orange": "Orange Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.pink": "Pink Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.purple": "Purple Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.red": "Red Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.white": "White Butterfly",
  "block.minecraft.banner.butterflies.banner_pattern_butterfly.yellow": "Yellow Butterfly",
  "item.butterflies.banner_pattern_butterfly": "Banner Pattern",
  "item.butterflies.banner_pattern_butterfly.desc": "Butterfly"

The final step is to add the new pattern to the banner pattern tags. To this I create banner_pattern_butterfly.json under \resources\data\<MOD_ID>\tags\banner_pattern\.

{
  "replace": false,
  "values": [
    "butterflies:banner_pattern_butterfly"
  ]
}

This links everything together, and now we can create and use a butterfly banner pattern in-game!

To finish off this feature, I add a recipe using silk and paper, and I also add it as a trade for the Master Lepidopterist. This gives players a way to access the pattern and start to create some butterfly-themed banners!

Wandering Trader Tweak


When testing the mod I noticed that the rare trades of almost all wandering traders were now rare butterflies. The vanilla trades almost never showed up. While I wanted players to be encouraged to find more butterflies, I didn’t want to effectively remove a vanilla feature. So I took another look at the design.

There are very few rare trades in the pool, so when I added the butterflies, most of the available trades become the new ones. There are 6 rare trades available by default, and I added 8. Since only one rare trade appears per trader, this meant that 57% of the time it would be a butterfly trade. This was a lot more common than I intended.

I decided to instead add the trades to the ordinary trade pool, and add uncommon butterflies instead. This means that players could still find less common butterflies this way, and that rare butterflies would be harder to find.

I booted up the game and spawned a bunch of wandering traders. Once I was happy that the new trades appeared often enough, but not too often, I committed the change. Now we can still have butterfly trades with the wandering trader, but players will still be able to buy their packed ice when they spot one.

Or they can just kill them for the free leashes. Either way works.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.