diff --git a/docs/blocks/index.md b/docs/blocks/index.md index ea54c393..8531a329 100644 --- a/docs/blocks/index.md +++ b/docs/blocks/index.md @@ -18,7 +18,7 @@ So now, let's register our blocks: ```java //BLOCKS is a DeferredRegister.Blocks -public static final DeferredBlock MY_BLOCK = BLOCKS.register("my_block", () -> new Block(...)); +public static final DeferredBlock MY_BLOCK = BLOCKS.register("my_block", registryName -> new Block(...)); ``` After registering the block, all references to the new `my_block` should use this constant. For example, if you want to check if the block at a given position is `my_block`, the code for that would look something like this: @@ -51,6 +51,8 @@ public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBloc For simple blocks which need no special functionality (think cobblestone, wooden planks, etc.), the `Block` class can be used directly. To do so, during registration, instantiate `Block` with a `BlockBehaviour.Properties` parameter. This `BlockBehaviour.Properties` parameter can be created using `BlockBehaviour.Properties#of`, and it can be customized by calling its methods. The most important methods for this are: +- `setId` - Sets the resource key of the block. + - This **must** be set on every block; otherwise, an exception will be thrown. - `destroyTime` - Determines the time the block needs to be destroyed. - Stone has a destroy time of 1.5, dirt has 0.5, obsidian has 50, and bedrock has -1 (unbreakable). - `explosionResistance` - Determines the explosion resistance of the block. @@ -68,8 +70,9 @@ So for example, a simple implementation would look something like this: //BLOCKS is a DeferredRegister.Blocks public static final DeferredBlock MY_BETTER_BLOCK = BLOCKS.register( "my_better_block", - () -> new Block(BlockBehaviour.Properties.of() + registryName -> new Block(BlockBehaviour.Properties.of() //highlight-start + .setId(ResourceKey.create(Registries.BLOCK, registryName)) .destroyTime(2.0f) .explosionResistance(10.0f) .sound(SoundType.GRAVEL) @@ -108,14 +111,14 @@ public class SimpleBlock extends Block { @Override public MapCodec codec() { - return SIMPLE_CODEC.value(); + return SIMPLE_CODEC.get(); } } // In some registration class public static final DeferredRegister> REGISTRAR = DeferredRegister.create(BuiltInRegistries.BLOCK_TYPE, "yourmodid"); -public static final DeferredHolder, MapCodec> SIMPLE_CODEC = REGISTRAR.register( +public static final Suppler> SIMPLE_CODEC = REGISTRAR.register( "simple", () -> simpleCodec(SimpleBlock::new) ); @@ -133,7 +136,7 @@ public class ComplexBlock extends Block { @Override public MapCodec codec() { - return COMPLEX_CODEC.value(); + return COMPLEX_CODEC.get(); } public int getValue() { @@ -144,14 +147,14 @@ public class ComplexBlock extends Block { // In some registration class public static final DeferredRegister> REGISTRAR = DeferredRegister.create(BuiltInRegistries.BLOCK_TYPE, "yourmodid"); -public static final DeferredHolder, MapCodec> COMPLEX_CODEC = REGISTRAR.register( +public static final Supplier> COMPLEX_CODEC = REGISTRAR.register( "simple", () -> RecordCodecBuilder.mapCodec(instance -> instance.group( Codec.INT.fieldOf("value").forGetter(ComplexBlock::getValue), BlockBehaviour.propertiesCodec() // represents the BlockBehavior.Properties parameter ).apply(instance, ComplexBlock::new) - ); + ) ); ``` @@ -173,7 +176,7 @@ public static final DeferredBlock EXAMPLE_BLOCK = BLOCKS.registerBlock( ); ``` -Internally, this will simply call `BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of()))` by applying the properties parameter to the provided block factory (which is commonly the constructor). +Internally, this will simply call `BLOCKS.register("example_block", registryName -> new Block(BlockBehaviour.Properties.of().setId(ResourceKey.create(Registries.BLOCK, registryName))))` by applying the properties parameter to the provided block factory (which is commonly the constructor). The id is set on the properties. If you want to use `Block::new`, you can leave out the factory entirely: diff --git a/docs/blocks/states.md b/docs/blocks/states.md index 906bf589..9dabb504 100644 --- a/docs/blocks/states.md +++ b/docs/blocks/states.md @@ -53,10 +53,6 @@ To implement a blockstate property, in your block class, create or reference a ` - Implements `Property`. Defines a property that can take on the values of an Enum class. - Created by calling `EnumProperty#create(String propertyName, Class enumClass)`. - It is also possible to use only a subset of the Enum values (e.g. 4 out of 16 `DyeColor`s), see the overloads of `EnumProperty#create`. -- `DirectionProperty` - - Extends `EnumProperty`. Defines a property that can take on a `Direction`. - - Created by calling `DirectionProperty#create(String propertyName)`. - - Several convenience predicates are provided. For example, to get a property that represents the cardinal directions, call `DirectionProperty.create("", Direction.Plane.HORIZONTAL)`; to get the X directions, `DirectionProperty.create("", Direction.Axis.X)`. The class `BlockStateProperties` contains shared vanilla properties which should be used or referenced whenever possible, in place of creating your own properties. @@ -72,7 +68,7 @@ To further illustrate this, this is what the relevant bits of the `EndPortalFram public class EndPortalFrameBlock extends Block { // Note: It is possible to directly use the values in BlockStateProperties instead of referencing them here again. // However, for the sake of simplicity and readability, it is recommended to add constants like this. - public static final DirectionProperty FACING = BlockStateProperties.FACING; + public static final EnumProperty FACING = BlockStateProperties.FACING; public static final BooleanProperty EYE = BlockStateProperties.EYE; public EndPortalFrameBlock(BlockBehaviour.Properties pProperties) { @@ -107,7 +103,7 @@ To go from `Block` to `BlockState`, call `Block#defaultBlockState()`. The defaul You can get the value of a property by calling `BlockState#getValue(Property)`, passing it the property you want to get the value of. Reusing our end portal frame example, this would look something like this: ```java -// EndPortalFrameBlock.FACING is a DirectionProperty and thus can be used to obtain a Direction from the BlockState +// EndPortalFrameBlock.FACING is an EnumPropery and thus can be used to obtain a Direction from the BlockState Direction direction = endPortalFrameBlockState.getValue(EndPortalFrameBlock.FACING); ``` @@ -138,9 +134,10 @@ To help setting the update flags correctly, there are a number of `int` constant - `Block.UPDATE_KNOWN_SHAPE` stops neighbor update recursion. - `Block.UPDATE_SUPPRESS_DROPS` disables block drops for the old block at that position. - `Block.UPDATE_MOVE_BY_PISTON` is only used by piston code to signal that the block was moved by a piston. This is mainly responsible for delaying light engine updates. +- `Block.UPDATE_SKIP_SHAPE_UPDATE_ON_WIRE` is used by the `ExperimentalRedstoneWireEvaluator` to signal if the shape should be skipped. This is set only when the power strength is changed from not a placement or that the original source on the signal is not the current wire. - `Block.UPDATE_ALL` is an alias for `Block.UPDATE_NEIGHBORS | Block.UPDATE_CLIENTS`. - `Block.UPDATE_ALL_IMMEDIATE` is an alias for `Block.UPDATE_NEIGHBORS | Block.UPDATE_CLIENTS | Block.UPDATE_IMMEDIATE`. -- `Block.NONE` is an alias for `Block.UPDATE_INVISIBLE`. +- `Block.UPDATE_NONE` is an alias for `Block.UPDATE_INVISIBLE`. There is also a convenience method `Level#setBlockAndUpdate(BlockPos pos, BlockState state)` that calls `setBlock(pos, state, Block.UPDATE_ALL)` internally.