User Tools

Site Tools


tutorial:blocks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial:blocks [2019/08/03 22:38]
fudge Added “next steps”
tutorial:blocks [2020/01/04 16:04] (current)
jamieswhiteshirt [Next Steps] Classes?
Line 24: Line 24:
 { {
     // block creation     // block creation
-    []+    [...]
     ​     ​
     @Override     @Override
Line 34: Line 34:
 </​code>​ </​code>​
  
-Your block will //not// be accessible as an item, but it can be seen in-game by using /​setblock ​~ ~ ~ tutorial:​example_block.+Your block will //not// be accessible as an item, but it can be seen in-game by using ''​/setblock tutorial:​example_block.''​
  
 ==== Registering a BlockItem ==== ==== Registering a BlockItem ====
Line 159: Line 159:
  
 Your custom block should now be transparent! Your custom block should now be transparent!
 +
 +
 +==== Custom VoxelShape ====
 +
 +When making custom blocks which do not entirely fill the block, the adjacent blocks might hide their faces. In this case of a custom vertical slab it would look like this:
 +
 +{{:​tutorial:​voxelshape_wrong.png?​200|}}
 +
 +
 +We have to define the VoxelShape of the new block into one which is not an entire block:
 +
 +<​code>​
 +@Override
 + ​public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext ctx) {
 +     ​return VoxelShapes.cuboid(0f,​ 0f, 0f, 1f, 1.0f, 0.5f);
 + }
 +</​code>​
 +
 +By doing so we also define getCollisionShape,​ because by default it returns the result of OutlineShape.
 +
 +{{:​tutorial:​voxelshape_fixed.png?​200|}}
 +
 ==== Next Steps ==== ==== Next Steps ====
 [[tutorial:​blockstate|Adding simple state to a block, like ints and booleans]]. ​ [[tutorial:​blockstate|Adding simple state to a block, like ints and booleans]]. ​
  
-[[tutorial:​blockentity|Giving blocks a block entity so they can have advanced state like inventories ​and classes]]. Also needed for many things like GUI and custom block rendering.+[[tutorial:​blockentity|Giving blocks a block entity so they can have advanced state like inventories]]. Also needed for many things like GUI and custom block rendering.
tutorial/blocks.1564871920.txt.gz · Last modified: 2019/08/03 22:38 by fudge