Changes

11 bytes removed ,  22:01, 30 July 2021
Update to 1.17
Line 5: Line 5:  
=== Basic Blocks ===
 
=== Basic Blocks ===
   −
For simple blocks, which need no special functionality (think cobblestone, wooden planks, etc.), a custom class is not necessary. You can create a block by instantiating the <code><nowiki>Block</nowiki></code> class with a <code><nowiki>AbstractBlock$Properties</nowiki></code> object. This <code><nowiki>AbstractBlock$Properties</nowiki></code> object can be made using <code><nowiki>AbstractBlock$Properties::create</nowiki></code> and it can be customised by calling its methods. For instance:
+
For simple blocks, which need no special functionality (think cobblestone, wooden planks, etc.), a custom class is not necessary. You can create a block by instantiating the <code><nowiki>Block</nowiki></code> class with a <code><nowiki>BlockBehaviour$Properties</nowiki></code> object. This <code><nowiki>BlockBehaviour$Properties</nowiki></code> object can be made using <code><nowiki>BlockBehaviour$Properties::of</nowiki></code> and it can be customised by calling its methods. For instance:
   −
* <code><nowiki>hardnessAndResistance</nowiki></code> - The hardness controls the time it takes to break the block. It is an arbitrary value. For reference, stone has a hardness of 1.5, and dirt 0.5. If the block should be unbreakable a hardness of -1.0 should be used, see the definition of <code><nowiki>Blocks#BEDROCK</nowiki></code> as an example. The resistance controls the explosion resistance of the block. For reference, stone has a resistance of 6.0, and dirt 0.5.
+
* <code><nowiki>strength</nowiki></code> - The hardness controls the time it takes to break the block. It is an arbitrary value. For reference, stone has a hardness of 1.5, and dirt 0.5. If the block should be unbreakable a hardness of -1.0 should be used, see the definition of <code><nowiki>Blocks#BEDROCK</nowiki></code> as an example. The resistance controls the explosion resistance of the block. For reference, stone has a resistance of 6.0, and dirt 0.5.
 
* <code><nowiki>sound</nowiki></code> - Controls the sound the block makes when it is punched, broken, or placed. Requires a <code><nowiki>SoundType</nowiki></code> argument, see the [[latest:advanced:effects:sounds|sounds]] page for more details.
 
* <code><nowiki>sound</nowiki></code> - Controls the sound the block makes when it is punched, broken, or placed. Requires a <code><nowiki>SoundType</nowiki></code> argument, see the [[latest:advanced:effects:sounds|sounds]] page for more details.
* <code><nowiki>setLightLevel</nowiki></code> - Controls the light emission of the block. Takes a function with a ''BlockState'' parameter that returns an integer value from zero to fifteen.
+
* <code><nowiki>lightLevel</nowiki></code> - Controls the light emission of the block. Takes a function with a ''BlockState'' parameter that returns an integer value from zero to fifteen.
* <code><nowiki>slipperiness</nowiki></code> - Controls how slippery the block is. For reference, ice has a slipperiness of 0.98.
+
* <code><nowiki>friction</nowiki></code> - Controls how slippery the block is. For reference, ice has a slipperiness of 0.98.
    
All these methods are ''chainable'' which means you can call them in series. See the <code><nowiki>Blocks</nowiki></code> class for examples of this.
 
All these methods are ''chainable'' which means you can call them in series. See the <code><nowiki>Blocks</nowiki></code> class for examples of this.
   −
{{Colored box|title=Tip|content=Blocks have no setter for their <code><nowiki>ItemGroup</nowiki></code>. This has been moved to the <code><nowiki>BlockItem</nowiki></code> and is now its responsibility.}}
+
{{Colored box|title=Tip|content=Blocks have no setter for their <code><nowiki>CreativeModeTab</nowiki></code>. This has been moved to the <code><nowiki>BlockItem</nowiki></code> and is now its responsibility.}}
    
=== Advanced Blocks ===
 
=== Advanced Blocks ===
Line 24: Line 24:  
Blocks must be [[Registration|registered]] to function.
 
Blocks must be [[Registration|registered]] to function.
   −
{{Tip/Important|A block in the world and a "block" in an inventory are very different things. A block in the world is represented by an <code><nowiki>BlockState</nowiki></code>, and its behavior defined by an instance of <code><nowiki>Block</nowiki></code>. Meanwhile, an item in an inventory is an <code><nowiki>ItemStack</nowiki></code>, controlled by an <code><nowiki>Item</nowiki></code>. As a bridge between the different worlds of <code><nowiki>Block</nowiki></code> and <code><nowiki>Item</nowiki></code>, there exists the class <code><nowiki>BlockItem</nowiki></code>. <code><nowiki>BlockItem</nowiki></code> is a subclass of <code><nowiki>Item</nowiki></code> that has a field <code><nowiki>block</nowiki></code> that holds a reference to the <code><nowiki>Block</nowiki></code> it represents. <code><nowiki>BlockItem</nowiki></code> defines some of the behavior of a "block" as an item, like how a right click places the block. It's possible to have a <code><nowiki>Block</nowiki></code> without an <code><nowiki>BlockItem</nowiki></code>. (E.g. <code><nowiki>minecraft:water</nowiki></code> exists as a block, but not an item. It is therefore impossible to hold it in an inventory as one.)
+
{{Tip/Important|A block in the level and a "block" in an inventory are very different things. A block in the level is represented by a <code><nowiki>BlockState</nowiki></code>, and its behavior defined by an instance of <code><nowiki>Block</nowiki></code>. Meanwhile, an item in an inventory is an <code><nowiki>ItemStack</nowiki></code>, controlled by an <code><nowiki>Item</nowiki></code>. As a bridge between the different worlds of <code><nowiki>Block</nowiki></code> and <code><nowiki>Item</nowiki></code>, there exists the class <code><nowiki>BlockItem</nowiki></code>. <code><nowiki>BlockItem</nowiki></code> is a subclass of <code><nowiki>Item</nowiki></code> that has a field <code><nowiki>block</nowiki></code> that holds a reference to the <code><nowiki>Block</nowiki></code> it represents. <code><nowiki>BlockItem</nowiki></code> defines some of the behavior of a "block" as an item, like how a right click places the block. It's possible to have a <code><nowiki>Block</nowiki></code> without an <code><nowiki>BlockItem</nowiki></code>. (E.g. <code><nowiki>minecraft:water</nowiki></code> exists as a block, but not an item. It is therefore impossible to hold it in an inventory as one.)
 
<br><br>
 
<br><br>
When a block is registered, ''only'' a block is registered. The block does not automatically have an <code><nowiki>BlockItem</nowiki></code>. To create a basic <code><nowiki>BlockItem</nowiki></code> for a block, one should use <code><nowiki>new BlockItem(block)</nowiki></code> and match the registry name between the two objects. Custom subclasses of <code><nowiki>BlockItem</nowiki></code> may be used as well. Once a <code><nowiki>BlockItem</nowiki></code> has been registered for a block, <code><nowiki>Block#asItem</nowiki></code> can be used to retrieve it. <code><nowiki>Block#asItem</nowiki></code> will deafult to <code><nowiki>Items#AIR</nowiki></code> if there is no <code><nowiki>BlockItem</nowiki></code> for the <code><nowiki>Block</nowiki></code>, so if you are not certain that there is an <code><nowiki>BlockItem</nowiki></code> for the <code><nowiki>Block</nowiki></code> you are using, check for <code><nowiki>Items#AIR</nowiki></code>.}}
+
When a block is registered, ''only'' a block is registered. The block does not automatically have an <code><nowiki>BlockItem</nowiki></code>. To create a basic <code><nowiki>BlockItem</nowiki></code> for a block, one should use <code><nowiki>new BlockItem(block)</nowiki></code> and match the registry name between the two objects. Custom subclasses of <code><nowiki>BlockItem</nowiki></code> may be used as well. Once a <code><nowiki>BlockItem</nowiki></code> has been registered for a block, <code><nowiki>Block#asItem</nowiki></code> can be used to retrieve it. <code><nowiki>Block#asItem</nowiki></code> will default to <code><nowiki>Items#AIR</nowiki></code> if there is no <code><nowiki>BlockItem</nowiki></code> for the <code><nowiki>Block</nowiki></code>, so if you are not certain that there is a <code><nowiki>BlockItem</nowiki></code> for the <code><nowiki>Block</nowiki></code> you are using, check for <code><nowiki>Items#AIR</nowiki></code>.}}
       
==== Optionally Registering Blocks ====
 
==== Optionally Registering Blocks ====
   −
Since there is no limit on the amount of blocks that can be register, register all blocks in your mod! If you want a block to be disabled through a configuration file, you should disable the crafting recipe and/or remove the block from the creative menu (<code><nowiki>ItemGroup</nowiki></code>).
+
Since there is no limit on the amount of blocks that can be register, register all blocks in your mod! If you want a block to be disabled through a configuration file, you should disable the crafting recipe and/or remove the block from the creative menu (<code><nowiki>CreativeModeTab</nowiki></code>).
    
== Further Reading ==
 
== Further Reading ==