CustomBlock constructor

CustomBlock(
  1. String id,
  2. Item item, {
  3. required Block block,
  4. Item? blockModel,
  5. Item? breakItem,
  6. Widget? main,
  7. Widget? onBreak,
  8. Widget? onPlaced,
  9. List<String> tags = const [],
  10. bool generatePack = true,
  11. bool fire = false,
  12. String? name,
  13. bool useItemFrame = false,
  14. double yOffset = 1,
})

This Module allows you to create infinite new blocks in the game. It works by providing a block and an item that acts as a model for the new block.

constructor
String unique id for your block
Item The item that should be used to place the block(you must use a spawnegg)
block the Block giving your custom block a hitbox(required)
blockModel Item that overrides the item for the block Model
breakItem The Item to kill if a player breaks the item(default = provided block)
main Widget that runs every tick in the block
onPlaced Widget that gets executed when the block is placed
onBreak Widget that gets executed when the block is broken
tag List of Strings of Tags to apply to the block entity
generatePack whether to generate the custom block as pack(default = true)
useItemFrame display the block in an invisible Item Frame(default = true)
fire set the entity on fire to hide graying out when using a solid block(default = false)

You can use getItem() on your created block to get the spawnegg with all the required nbt data. This can be used further.

When using the spawnegg an invisible armorstand or itemframe will spawn displaying the block model. This gives the illusion that this is a new block.

With CustomModelData (model in objD) you can make as many of these as you want.

Example:

import 'package:objd/custom_block.dart';

CustomBlock(
	'creative_name',
	Item(
		Items.chicken_spawn_egg,model: 2,
		name: TextComponent('Creative Block'),
	),
	block: Blocks.stone,
	useItemFrame: false,
	generatePack: false,
)

Implementation

CustomBlock(
  this.id,
  this.item, {
  required this.block,
  this.blockModel,
  Item? breakItem,
  this.main,
  this.onBreak,
  this.onPlaced,
  this.tags = const [],
  this.generatePack = true,
  this.fire = false,
  this.name,
  this.useItemFrame = false,
  this.yOffset = 1,
})  : breakItem = breakItem ?? Item(block),
      assert(
        item.getId().contains('spawn_egg'),
        'You have to provide a spawn egg.',
      );