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

 Hi,

in the documentation of forge (1.16.x) I've found this quote:

"If you are placing a Block, call Block#getDefaultState() to get the “default” state(...)"

Now when I try to use code such as below:

BlockState newBlockState = Blocks.DIRT.getDefaultState();

I get this error:

/home/poison64/dev/mc-forge/first/src/main/java/com/example/examplemod/MyModEventHandler.java:23: error: cannot find symbol
        BlockState newBlockState = Blocks.DIRT.getDefaultState();
                                              ^
  symbol:   method getDefaultState()
  location: variable DIRT of type Block
1 error

Is the documentation wrong or I just don't know something?

I've played around with other stuff, and they work just fine, for example, this one works as expected:

    @SubscribeEvent
    public void pickupItem(EntityItemPickupEvent event) {
        ItemStack stack = event.getItem().getItem();
        stack.setCount(stack.getCount()*2);         
    }

 

  • Author

@diesieben07, thank You for your answer :)

Just one follow up... So how do people actually learn these things? Just by scouring the forums, random tutorial pages and source codes?

  • 1 year later...
On 4/4/2021 at 12:06 PM, diesieben07 said:

Most documentation has not been updated for the recent switch to Mojang names. The method is now called defaultBlockState.

Please help, how called method .with

public class RotateBlockModel extends HorizontalBlock {
    public RotateBlockModel(Properties builder) {
        super(builder);
    }
    
    public void fillStateContainer(StateContainer.Builder<Block, BlockState> builder){
        builder.add(FACING);
    }

    @Nullable
    @Override
    public BlockState getStateForPlacement(BlockItemUseContext context) {
        return this.getBlock().defaultBlockState().with;
    }
}
C:\Users\������\OneDrive\������� ����\����\mod\src\main\java\com\dipcrai\mymod\block\custom\RotateBlockModel.java:23: error: cannot find symbol
        return this.getBlock().defaultBlockState().with();
                                                  ^

 

  • Guest locked this topic
Guest
This topic is now closed to further replies.

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.