javaminecraft-forge

1.20 Minecraft Forge Block Rotation


Trying to make a small personal mod for this server I'm in, using MC Forge for 1.20.1. We want to have custom bed models. I've got just about everything working except for a few things. For some reason I cannot figure out how to get the rotational block placement down. All my code looks correct so far, I've got a class to check for block placement, a block states and items and such. The block will place just fine until I try to add in block states then turns into a purple and black error block.

Going through documentation I've tried changing how the class is called, how the block registry is. I've changed the block states multiple times and when the block states are only something like

{
  "variants": {
    "": {
      "model": "tutorial_testing:block/hope_bed"
    }
  }
}

The bed is then able to show up but once I try to put in something like:

{
  "variants": {
    "facing = north": {
      "model": "tutorial_testing:block/hope_bed"},
    "facing = east": {
        "model": "tutorial_testing:block/hope_bed",
        "y": 90
      },
    "facing = south": {
        "model": "tutorial_testing:block/hope_bed",
        "y": 180
      },
    "facing = west": {
        "model": "tutorial_testing:block/hope_bed",
        "y": 270
    }
  }
}

The block turns into the purple and black texture block. I know it's something to do with how it cannot find the textures but cannot for the life of me figure out why.

Editing to add more code I forgor sorry

Block Registry:

import io.github.magikpups.testing.TestingMod;
import io.github.magikpups.testing.block.advhopebed;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class BlockRegistry {
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS,
            TestingMod.MOD_ID);

    public static final RegistryObject<Block> HOPE_BED = BLOCKS.register(
            "hope_bed", () -> new advhopebed(Block.Properties.copy(Blocks.BAMBOO_PLANKS)
                    .mapColor(MapColor.COLOR_LIGHT_GREEN)
                    .strength(5.0f)
                    .sound(SoundType.BAMBOO_WOOD)
                    .noLootTable()
                    .dynamicShape()
            ));
}

Class advhopebed:

import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;

public class advhopebed extends HorizontalDirectionalBlock {

    public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

    public advhopebed(Properties properties) {
        super(properties);
    }

    public BlockState getStateForPlacement(BlockPlaceContext context) {
        return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
    }

    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        super.createBlockStateDefinition(builder);
        builder.add(FACING);
    }
}

Edit: Found what the issue was, I am not suppose to put spaces for facing=north. Just thought I put this here in case anyone else had an issue :>


Solution

  • Figured it out. Code is suppose to go something like this.

    {
      "variants": {
        "facing=north": {
          "model": "tutorial_testing:block/hope_bed"},
        "facing=east": {
            "model": "tutorial_testing:block/hope_bed",
            "y": 90
          },
        "facing=south": {
            "model": "tutorial_testing:block/hope_bed",
            "y": 180
          },
        "facing=west": {
            "model": "tutorial_testing:block/hope_bed",
            "y": 270
        }
      }
    }