For full source code see:
https://github.com/BrasilianEngineer/WarehouseMod/tree/master/src/main/java/com/brasilianengineer/tbewarehouse
https://github.com/BrasilianEngineer/WarehouseMod/tree/master/src/main/resources/assets/tbewarehouse
I'm currently trying to work with:
1 item
1 simple block
2 metadata blocks w/ 2 versions each.
The blocks render correctly when I place them in world, but don't in my hand or my inventory.
If I can figure out the item and the simple block, I can hopefully figure out the rest from there.
Block Registration:
@GameRegistry.ObjectHolder(Reference.MOD_ID)
public class ModBlocks {
public static final BlockTWM machineFrame = new BlockWarehouseFrame();
public static final BlockTWM machineWall = new BlockWarehouseWall();
public static void init() { // called from common proxy preInit
GameRegistry.registerBlock(machineFrame, ItemBlockTWMWarehouseFrameVariants.class, Names.Blocks.BLOCK_WAREHOUSE_FRAME);
GameRegistry.registerBlock(machineWall, ItemBlockTWMWarehouseFrameVariants.class, Names.Blocks.BLOCK_WAREHOUSE_WALL);
LogHelper.info("Block Registry Init Complete");
}
}
Block Render Registry:
public final class BlockRenderRegister {
public static void init() {
registerBlockVariant(ModBlocks.warehouseFrame);
registerBlockVariant(ModBlocks.warehouseWall);
registerBlock(ModBlocks.warehouseBuffer);
LogHelper.info("Block Render Registry Init Complete");
}
private static void registerBlock(Block block) {
Item item = GameRegistry.findItem(Reference.MOD_ID, block.getUnlocalizedName().substring(5));
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(Reference.RESOURCE_PREFIX + block.getUnlocalizedName().substring(5), "inventory"));
}
private static void registerBlockVariant(Block block) {
String baseName = block.getUnlocalizedName().substring(5);
Item item = GameRegistry.findItem(Reference.MOD_ID, baseName);
for(BlockWarehouseFrameComponent.EnumType type : BlockWarehouseFrameComponent.EnumType.values()) {
ModelResourceLocation itemModelResourceLocation = new ModelResourceLocation(Reference.RESOURCE_PREFIX + baseName + "_" + type.getName(), "inventory");
ModelLoader.setCustomModelResourceLocation(item, type.getMetadata(), itemModelResourceLocation);
}
}
}
Simple Block Class (they are all almost the same)
public class BlockWarehouseBuffer extends BlockWarehouseInternalComponent {
public BlockWarehouseBuffer() {
super();
this.setUnlocalizedName(Names.Blocks.BLOCK_WAREHOUSE_BUFFER);
}
}
Block Base Class
public class BlockWarehouseInternalComponent extends BlockTWM {
public BlockWarehouseInternalComponent() {
super(Material.iron);
setHardness(5.0f);
setResistance(25.0f);
setHardness(1f);
setStepSound(SoundType.METAL);
}
}
public class BlockTWM extends Block {
public BlockTWM(Material material) {
super(material);
setCreativeTab(CreativeTabTWM.TWM_TAB);
}
}
Item json
{
"parent": "builtin/generated",
"textures": {
"layer0":"tbewarehouse:items/multi_tool"
},
"display": {
"thirdperson": {
"rotation": [ -90, 0, 0 ],
"translation": [ 0, 1, -3 ],
"scale": [ 0.55, 0.55, 0.55 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}
Simple Block Blockstate
{
"variants": {
"normal": { "model": "tbewarehouse:warehouse_buffer" }
}
}
Simple Block Model
{
"parent": "block/cube_all",
"textures": {
"all": "tbewarehouse:blocks/warehouse_buffer_all"
}
}
Simple Block Item Model
{
"parent": "tbewarehouse:block/warehouse_buffer",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}
Forge Log