Version: 1.20+
This section will cover the process around creating bucket textures for your fluids utilizing FabricModelProvider
. This is useful if you plan to have many fluids whose texture will be similar to the Water Bucket texture.
While this guide is specifically tailored towards buckets, it can be applied to anything with enough creativity.
Data Generation
within your project.Fluid
.this bucket overlay texture
(Right Click → Save Image As) and insert it into src/main/resources/assets/modid/textures/item/
.
We will need to create a new file named template_bucket.json
in our src/main/resources/assets/modid/models/item/
folder:
{ "parent": "item/generated", "textures": { "layer0": "item/bucket", "layer1": "examplemod:item/custom_bucket_overlay" } }
To get started, we will need to have a custom bucket class that takes in a int fluidColor
. You can introduce your bucket logic here, or extent this class for other types of bucket use cases.
import net.minecraft.fluid.Fluids; import net.minecraft.item.BucketItem; import net.minecraft.item.Item; public class CustomBucket extends BucketItem { private final int fluidColor; public CustomBucket(Item.Settings settings, int fluidColor) { super(Fluids.WATER, settings); this.fluidColor = fluidColor; } public int getColor(int tintIndex) { return tintIndex == 1 ? fluidColor: -1; } }
Here our getColor(int tintIndex)
will return the defined fluidColor
value when our tintIndex
is 1
(this can be associated with the number of the texture layer). By returning -1
, we are saying that the color should remain as is in the image (which in this case is our base bucket image).
Inside of our ExampleMod.java
class, we will create and register our new bucket items. (This implementation location may vary based on your project.)
public class ExampleMod implements ModInitializer { public static final String MODID = "examplemod"; public static final Item RED_WATER_BUCKET = new CustomBucket(new FabricItemSettings(), 12320768); public static final Item GREEN_WATER_BUCKET = new CustomBucket(new FabricItemSettings(), 48128); public static final Item BLUE_WATER_BUCKET = new CustomBucket(new FabricItemSettings(), 188); @Override public void onInitialize() { Registry.register(Registries.ITEM, new Identifier(MODID, "red_water_bucket"), RED_WATER_BUCKET); Registry.register(Registries.ITEM, new Identifier(MODID, "green_water_bucket"), GREEN_WATER_BUCKET); Registry.register(Registries.ITEM, new Identifier(MODID, "blue_water_bucket"), BLUE_WATER_BUCKET); } }
Somewhere along the way you will want to create a helper method to create models for you, so why not now?!
In a util class, or even inside of your Data Generator class lets add the following method:
public static Model item(String parent) { return new Model(Optional.of(new Identifier(ExampleMod.MODID, "item/" + parent)), Optional.empty()); }
This code will create a Model
with a reference to our template bucket model.
Inside of your FabricModelProvider
implementation, we will add the following lines to the generateItemModels(ItemModelGenerator itemModelGenerator)
method:
@Override public void generateItemModels(ItemModelGenerator itemModelGenerator) { itemModelGenerator.register(ExampleMod.RED_WATER_BUCKET, item("template_bucket")); itemModelGenerator.register(ExampleMod.GREEN_WATER_BUCKET, item("template_bucket")); itemModelGenerator.register(ExampleMod.BLUE_WATER_BUCKET, item("template_bucket")); }
We pass in template_bucket
to the item()
method, as that is the parent model our bucket models will follow.
Last thing to get all of this implemented is to register the bucket coloring on the client. To do this we go into the onInitializeClient
method inside of ExampleModClient
@Override public void onInitializeClient() { ColorProviderRegistry.ITEM.register((stack, tintIndex) -> ((CustomBucket) stack.getItem()).getColor(tintIndex), ExampleMod.RED_WATER_BUCKET, ExampleMod.GREEN_WATER_BUCKET, ExampleMod.BLUE_WATER_BUCKET); }
Now that we have reached the end, upon starting up minecraft and joining a world, we should be able to /give @a examplemod:red_water_bucket
and see we now have a red water bucket! (I'll leave adding translations and item grouping to you! )