Jump to content

[1.8] Stairs


localtoast9001

Recommended Posts

Stairs are easier than slabs. For complete source listing look at https://github.com/localtoast9001/forge-mods/tree/1.8.

 

How stairs work in the game

Each stair is a block derived from net.minecraft.block.BlockStairs. The base class controls collision, placement, and block state properties. The stairs block references its full cube block object for material properties. The stairs block has a lot of different variants through its block state to describe the stair's orientation. Since each variant potentially has its own model, you'll need to test all combinations.

 

Design Considerations

I originally wanted to do stairs for stained bricks. The cube block for stained bricks is one block with 16 variants for each color. In 1.7, the stairs block uses all the metadata for orientation, so I needed 16 different types of stairs. I continued this pattern in 1.8, even though BlockStairs now takes a full IBlockState in its constructor. I didn't experiment.

 

Classes you will need

A stairs block class derived from net.minecraft.block.BlockStairs - This is used for block registration and to initialize the base class with properties from the cube block. To get a block state object from the cube block, you can call block.getStateFromMeta(int metadata). metadata is 0 if your cube block has no variants.

Example:

/**
* Stained brick stairs.
*
*/
public class BlockStainedBrickStairs extends BlockStairs {
    /**
     * Initializes a new instance of the BlockStainedBrickStairs class.
     * @param block the stained bricks block.
      */
    public BlockStainedBrickStairs(
        final BlockStainedBricks block) {
        super(block.getStateFromMeta(0));

 

Block Registration

Stairs reuse the common ItemBlock class, so stairs are registered like any other normal block in your Mod's init event handler.

Example:

            BlockStainedBrickStairs stairs = new BlockStainedBrickStairs(
                stainedBrickBlocks);
            GameRegistry.registerBlock(stairs, stairs.getId());

Models

You need one blockstate file and 3 model files (normal, inner, and outer) for your stairs.

Example/template blockstate file:

{
    "variants": {
        "facing=east,half=bottom,shape=straight":  { "model": "morematerials:stained_bricks_block_black_stairs" },
        "facing=west,half=bottom,shape=straight":  { "model": "morematerials:stained_bricks_block_black_stairs", "y": 180, "uvlock": true },
        "facing=south,half=bottom,shape=straight": { "model": "morematerials:stained_bricks_block_black_stairs", "y": 90, "uvlock": true },
        "facing=north,half=bottom,shape=straight": { "model": "morematerials:stained_bricks_block_black_stairs", "y": 270, "uvlock": true },
        "facing=east,half=bottom,shape=outer_right":  { "model": "morematerials:stained_bricks_block_black_outer_stairs" },
        "facing=west,half=bottom,shape=outer_right":  { "model": "morematerials:stained_bricks_block_black_outer_stairs", "y": 180, "uvlock": true },
        "facing=south,half=bottom,shape=outer_right": { "model": "morematerials:stained_bricks_block_black_outer_stairs", "y": 90, "uvlock": true },
        "facing=north,half=bottom,shape=outer_right": { "model": "morematerials:stained_bricks_block_black_outer_stairs", "y": 270, "uvlock": true },
        "facing=east,half=bottom,shape=outer_left":  { "model": "morematerials:stained_bricks_block_black_outer_stairs", "y": 270, "uvlock": true },
        "facing=west,half=bottom,shape=outer_left":  { "model": "morematerials:stained_bricks_block_black_outer_stairs", "y": 90, "uvlock": true },
        "facing=south,half=bottom,shape=outer_left": { "model": "morematerials:stained_bricks_block_black_outer_stairs" },
        "facing=north,half=bottom,shape=outer_left": { "model": "morematerials:stained_bricks_block_black_outer_stairs", "y": 180, "uvlock": true },
        "facing=east,half=bottom,shape=inner_right":  { "model": "morematerials:stained_bricks_block_black_inner_stairs" },
        "facing=west,half=bottom,shape=inner_right":  { "model": "morematerials:stained_bricks_block_black_inner_stairs", "y": 180, "uvlock": true },
        "facing=south,half=bottom,shape=inner_right": { "model": "morematerials:stained_bricks_block_black_inner_stairs", "y": 90, "uvlock": true },
        "facing=north,half=bottom,shape=inner_right": { "model": "morematerials:stained_bricks_block_black_inner_stairs", "y": 270, "uvlock": true },
        "facing=east,half=bottom,shape=inner_left":  { "model": "morematerials:stained_bricks_block_black_inner_stairs", "y": 270, "uvlock": true },
        "facing=west,half=bottom,shape=inner_left":  { "model": "morematerials:stained_bricks_block_black_inner_stairs", "y": 90, "uvlock": true },
        "facing=south,half=bottom,shape=inner_left": { "model": "morematerials:stained_bricks_block_black_inner_stairs" },
        "facing=north,half=bottom,shape=inner_left": { "model": "morematerials:stained_bricks_block_black_inner_stairs", "y": 180, "uvlock": true },
        "facing=east,half=top,shape=straight":  { "model": "morematerials:stained_bricks_block_black_stairs", "x": 180, "uvlock": true },
        "facing=west,half=top,shape=straight":  { "model": "morematerials:stained_bricks_block_black_stairs", "x": 180, "y": 180, "uvlock": true },
        "facing=south,half=top,shape=straight": { "model": "morematerials:stained_bricks_block_black_stairs", "x": 180, "y": 90, "uvlock": true },
        "facing=north,half=top,shape=straight": { "model": "morematerials:stained_bricks_block_black_stairs", "x": 180, "y": 270, "uvlock": true },
        "facing=east,half=top,shape=outer_right":  { "model": "morematerials:stained_bricks_block_black_outer_stairs", "x": 180, "uvlock": true },
        "facing=west,half=top,shape=outer_right":  { "model": "morematerials:stained_bricks_block_black_outer_stairs", "x": 180, "y": 180, "uvlock": true },
        "facing=south,half=top,shape=outer_right": { "model": "morematerials:stained_bricks_block_black_outer_stairs", "x": 180, "y": 90, "uvlock": true },
        "facing=north,half=top,shape=outer_right": { "model": "morematerials:stained_bricks_block_black_outer_stairs", "x": 180, "y": 270, "uvlock": true },
        "facing=east,half=top,shape=outer_left":  { "model": "morematerials:stained_bricks_block_black_outer_stairs", "x": 180, "y": 90, "uvlock": true },
        "facing=west,half=top,shape=outer_left":  { "model": "morematerials:stained_bricks_block_black_outer_stairs", "x": 180, "y": 270, "uvlock": true },
        "facing=south,half=top,shape=outer_left": { "model": "morematerials:stained_bricks_block_black_outer_stairs", "x": 180, "y": 180, "uvlock": true },
        "facing=north,half=top,shape=outer_left": { "model": "morematerials:stained_bricks_block_black_outer_stairs", "x": 180, "uvlock": true },
        "facing=east,half=top,shape=inner_right":  { "model": "morematerials:stained_bricks_block_black_inner_stairs", "x": 180, "uvlock": true },
        "facing=west,half=top,shape=inner_right":  { "model": "morematerials:stained_bricks_block_black_inner_stairs", "x": 180, "y": 180, "uvlock": true },
        "facing=south,half=top,shape=inner_right": { "model": "morematerials:stained_bricks_block_black_inner_stairs", "x": 180, "y": 90, "uvlock": true },
        "facing=north,half=top,shape=inner_right": { "model": "morematerials:stained_bricks_block_black_inner_stairs", "x": 180, "y": 270, "uvlock": true },
        "facing=east,half=top,shape=inner_left":  { "model": "morematerials:stained_bricks_block_black_inner_stairs", "x": 180, "y": 90, "uvlock": true },
        "facing=west,half=top,shape=inner_left":  { "model": "morematerials:stained_bricks_block_black_inner_stairs", "x": 180, "y": 270, "uvlock": true },
        "facing=south,half=top,shape=inner_left": { "model": "morematerials:stained_bricks_block_black_inner_stairs", "x": 180, "y": 180, "uvlock": true },
        "facing=north,half=top,shape=inner_left": { "model": "morematerials:stained_bricks_block_black_inner_stairs", "x": 180, "uvlock": true }
    }
}

Normal stairs model example/template:

{
    "parent": "block/stairs",
    "textures": {
        "bottom": "morematerials:blocks/stainedbricks_black",
        "top": "morematerials:blocks/stainedbricks_black",
        "side": "morematerials:blocks/stainedbricks_black"
    }
}

Inner stairs model example/template:

{
    "parent": "block/inner_stairs",
    "textures": {
        "bottom": "morematerials:blocks/stainedbricks_black",
        "top": "morematerials:blocks/stainedbricks_black",
        "side": "morematerials:blocks/stainedbricks_black"
    }
}

Outer model example/template:

{
    "parent": "block/outer_stairs",
    "textures": {
        "bottom": "morematerials:blocks/stainedbricks_black",
        "top": "morematerials:blocks/stainedbricks_black",
        "side": "morematerials:blocks/stainedbricks_black"
    }
}

Quirks

Using Neighbor brightness - In your stairs block class, set the useNeighborBrightness property to true. Otherwise, you will get dark spots on neighboring bricks when you place the stairs.

        this.useNeighborBrightness = true;

Model Registration - Like any other block in 1.8, the model has to be registered for display as an inventory icon. There are other posts on the subject, but essentially you need to do the following:

        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(
                item,
                metadata,
                new ModelResourceLocation(
                    MODID + id,
                    "inventory"));

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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