Jump to content

Blocks#getDefaultState


poison64

Recommended Posts

 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);         
    }

 

Link to comment
Share on other sites

  • 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();
                                                  ^

 

Link to comment
Share on other sites

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

Announcements



×
×
  • Create New...

Important Information

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