Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So I am trying to generate crop blockstate.json files by using BlockStateProvider.

I'm not finding a method in the class handling crops.

I guess it has to be done with the VariantBuilder from getVariantBuilder(BLOCK).forAllStates(state -> ...), 

from what I understand the function takes returns ConfiguredModel[] but how I am supposed to add definitions for each variant?

Documentation is not very clear, can someone briefly explain how does this work.

I'm using Forge 40.1.86 for 1.18.2.

Generated JSON's should look like this:

{
  "variants": {
    "age=0": {
      "model": "examplemod:block/example_crop_stage0"
    },
    "age=1": {
      "model": "examplemod:block/example_crop_stage0"
    },
    "age=2": {
      "model": "examplemod:block/example_crop_stage1"
    },
    "age=3": {
      "model": "examplemod:block/example_crop_stage1"
    },
    "age=4": {
      "model": "examplemod:block/example_crop_stage2"
    },
    "age=5": {
      "model": "examplemod:block/example_crop_stage2"
    },
    "age=6": {
      "model": "examplemod:block/example_crop_stage2"
    },
    "age=7": {
      "model": "examplemod:block/example_crop_stage3"
    }
  }
}

 

  • Author

It's my bad I forgot about the online docs, I meant there was not enough documentation in the IDE when looking through the classes.

I got it to work now.

public class ModBlockStateProvider extends BlockStateProvider {
    public ModBlockStateProvider(DataGenerator gen, String modid, ExistingFileHelper exFileHelper) {
        super(gen, modid, exFileHelper);
    }

    @Override
    protected void registerStatesAndModels() {
        addCropBlock(ModBlocks.TOMATOES.get());
    }

    public void addCropBlock(Block pBlock) {
        this.getVariantBuilder(pBlock)
                .forAllStates(state -> 
                        ConfiguredModel.builder()
                                .modelFile(
                                        models().getExistingFile(
                                           modLoc(pBlock.getRegistryName().getPath() + "_stage" + state.getValue(((CropBlock) pBlock).getAgeProperty()))
                                        )
                                )
                                .build()
                );
    }
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.