legoatoom / ConnectibleChains

Connect your fences with a decorative chain!
GNU Lesser General Public License v3.0
14 stars 6 forks source link

Handle getTexture method differently #53

Closed Dbl7id closed 3 months ago

Dbl7id commented 11 months ago

Mythic Metals Decorations handle textures for their items differently from what the mod is expecting, so chain knot textures are just missing.

    private Identifier getKnotTexture(Item item) {
        Identifier id = Registries.ITEM.getId(item);
        return new Identifier(id.getNamespace(), "textures/item/" + id.getPath() + ".png");
    }

You can see here in the image that the knot textures are missing but the chain textures are present. image

This is due to the fact that the chain item textures are stored in a different folder under /item/chain/, as seen here. image

The options are to either: a) Try to change how this method looks the texture and probably check inside folders, or we can also narrow it down to a chain folder, until it finds the needed textures. b) Special case the mod so that it checks for textures differently.

I went for option b, as I highly doubt that the number of mods that store these textures differently, and also add chains couldn't be counted on two hands:

    private Identifier getKnotTexture(Item item) {
        Identifier id = Registries.ITEM.getId(item);
        if (id.getNamespace().equals("mythicmetals_decorations"))
            return new Identifier(id.getNamespace(), "textures/item/chain/" + id.getPath() + ".png");

        return new Identifier(id.getNamespace(), "textures/item/" + id.getPath() + ".png");
    }

With the code above, we get the proper results in-game. image

Edit: I just looked at PR #18 and saw how mod detection was handled. Should I do that for this piece of code instead?(Disregard this as doing this causes all chains to look for textures differently)

    private Identifier getKnotTexture(Item item) {
        Identifier id = Registries.ITEM.getId(item);
        if (FabricLoader.getInstance().isModLoaded("mythicmetals_decorations"))
            return new Identifier(id.getNamespace(), "textures/item/chain/" + id.getPath() + ".png");

        return new Identifier(id.getNamespace(), "textures/item/" + id.getPath() + ".png");
    }

I'm not very familiar with the Fabric ecosystem so I wouldn't know if this is a better method for the same result.

I also noticed that for the mod Clutter, when I register the copper chains, the mod also automatically registers the waxed variants, but it has no idea where to grab the textures in that case as it's not considered a different item but rather a as blockstate of the chains so it just shares the same textures as the regular variant.

How should I go about fixing this in a proper manner?

legoatoom commented 11 months ago

I will look into changing it as there are some things I would like to do differently. What you proposed is probably the a good solution.

Qendolin had in the past the idea to allow users to create custom JSON files that specify custom chains, and where their textures are located, instead of using the item tag system, but we had problems understanding how custom data files work and how they sync between server-client.

Perhaps I could take another look at it and fall back to the better system you proposed. I will most likely start working when a new Minecraft update arrives because then I will have more pressure to update the mod anyway.

Dbl7id commented 11 months ago

I just realized the second edit I made probably ends up making all chains check for textures in the chains folder when Mythic Metals Decorations is loaded.

So the first one I made should be the proper one.

legoatoom commented 3 months ago

In the newest version (1.20.6) you can create a model file where you locate the texture. See : https://github.com/legoatoom/ConnectibleChains/blob/1.20.6/src/main/resources/assets/minecraft/models/entity/connectiblechains/chain.json

{
  "textures": {
    "chain": "minecraft:textures/block/chain",
    "knot": "minecraft:textures/item/chain"
  }
}

The only issue is that there is one chain that has an animated texture. I could not find a fix for this. The mod cannot render animated textures, so you would need to make a static texture for it and use that as the chain texture.