Adding a custom Trellis variant - Heccology/Bountiful-Fares GitHub Wiki

Registration

Trellis variants can be created by creating a new instance of the TrellisVariant class. This is what an example registry of a new Trellis type would look like:

public class ExampleModTrellises {
    public static final ArrayList<Block> TRELLIS_RENDER_CUTOUT = new ArrayList<>();

    public static final TrellisVariant REDWOOD = new TrellisVariant("exampletrellises", "redwood", REDWOOD_PLANKS.asItem(), TRELLIS_RENDER_CUTOUT);
}

The first parameter is your mod id and is used to specify what mod id it will register trellis blocks under.

The second parameter is the name/id of the trellis variant. (dont include "trellis" in the name, it is added automatically)

The third parameter is the planks item for the wood type of the trellis - this is used for generating the crafting recipe. Can be null if you are going to use a custom recipe for it.

The TRELLIS_RENDER_CUTOUT list is used for specifying the render layer that the Trellis blocks should be on. it is given when registering a Trellis variant as it automatically adds the block generated to the list which you can use.

This is what your mod's client initialization class should look like:

public void onInitializeClient() {
    for (Block block : ExampleModTrellises.TRELLIS_RENDER_CUTOUT) {
        BlockRenderLayerMap.INSTANCE.putBlock(block, RenderLayer.getCutout());
    }
}

This ensures that the texture of your trellis variant is transparent.


The following code can be copied into your data generation class(es) to generate the other files needed for the Trellis variant:

Loot Table Generation

    @Override
    public void generate() {
            registerTrellisLootTables(ExampleModTrellises.REDWOOD);
    }


    public void registerTrellisLootTables(TrellisVariant trellis) {
        addDrop(TrellisUtil.getTrellisFromVariant(trellis));
        for (VineCrop crop : TrellisVariants.VineCrops) {
            addDrop(TrellisUtil.getCropTrellisFromVariant(trellis, crop), LootTable.builder()
                    .pool(LootPool.builder().rolls(ConstantLootNumberProvider.create(1.0F))
                            .with(this.applyExplosionDecay(TrellisUtil.getCropTrellisFromVariant(trellis, crop), ItemEntry.builder(TrellisUtil.getTrellisFromVariant(trellis))))));
        }
        for (DecorativeVine vine : TrellisVariants.DecorativeVines) {
            addDrop(TrellisUtil.getDecorTrellisFromVariant(trellis, vine), LootTable.builder()
                    .pool(LootPool.builder().rolls(ConstantLootNumberProvider.create(1.0F))
                            .with(this.applyExplosionDecay(TrellisUtil.getDecorTrellisFromVariant(trellis, vine), ItemEntry.builder(TrellisUtil.getTrellisFromVariant(trellis))))));
        }
    }

Block Model Generation

    @Override
    public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
        TrellisUtil.registerTrellisModels(blockStateModelGenerator, ExampleModTrellises.REDWOOD);
    }

Recipe Generation

    @Override
    public void generate(Consumer<RecipeJsonProvider> exporter) {
        TrellisUtil.registerTrellisRecipe(exporter, ExampleModTrellises.REDWOOD);
    }

If you did not specify a planks item when registering a Trellis Variant, this will not work. You will need to create a custom recipe, like this:

    ShapedRecipeJsonBuilder.create(RecipeCategory.DECORATIONS, getTrellisFromVariant(ExampleModTrellises.GOLD))
                .pattern("# #")
                .pattern(" # ")
                .pattern("# #")
                .input('#', Items.GOLD_NUGGET)
                .criterion("has_gold",
                        RecipeProvider.conditionsFromItem(Items.GOLD_NUGGET))
                .group("trellis")
                .offerTo(exporter);

Methods

There are a few methods you can use to get certain values of a Trellis variant:

.getVariantName() - gets the name/id of the Trellis variant (for example, "redwood")

.getBlockName() - gets the name/id of the Trellis that would be used for the block id (for example, "redwood_trellis")

.getModId() - gets the mod id that the Trellis variant is registered in (for example, "examplemod")

.getCraftingItem() - gets the item used to craft the Trellis variant. Will return null if it wasnt specified (for example, REDWOOD_PLANKS)


To refer to a specific Trellis, you can use the .getTrellisFromVariant(), .getCropTrellisFromVariant(), and .getDecorTrellisFromVariant() methods in the TrellisUtil class. As an example, you could use this code to add a Redwood Trellis to an item group:

entries.add(TrellisUtil.getTrellisFromVariant(ExampleModTrellises.REDWOOD))

NOTE: Custom vine crops and decorative vines aren't possible due to technical limitations.

⚠️ **GitHub.com Fallback** ⚠️