Jump to content

How do I assign a texture to a block?


Linky132

Recommended Posts

Hi, so I very recently decided to get into modding, and I've managed to make a block using this tutorial. However, when I follow the part to add a model and texture to the block, only the ItemBlock (the block when it's in my inventory) has a model and texture. Does anyone know how I can give the actual block a model and a texture? Thanks!

Link to comment
Share on other sites

Mod class:

package cubicoder.tutorialmod;

import cubicoder.tutorialmod.init.ModBlocks;
import linky132.waywardcraft.WaywardCraft;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@EventBusSubscriber(modid = WaywardCraft.MODID)
public class RegistrationHandler {

    @SubscribeEvent
    public static void registerItems(Register<Item> event) {

        final Item[] itemBlocks = {
                new ItemBlock(ModBlocks.first_block).setRegistryName(ModBlocks.first_block.getRegistryName())

        };

        event.getRegistry().registerAll(itemBlocks);
    }

    @SubscribeEvent
    public static void registerBlocks(Register<Block> event) {
        final Block[] blocks = {
                new Block(Material.ROCK).setRegistryName(WaywardCraft.MODID, "first_block").setCreativeTab(CreativeTabs.MISC)
        };

        event.getRegistry().registerAll(blocks);
    }
}

ModBlocks class:

package cubicoder.tutorialmod.init;

import linky132.waywardcraft.WaywardCraft;
import net.minecraft.block.Block;
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;

@ObjectHolder(WaywardCraft.MODID)
public class ModBlocks {

    public static final Block first_block = null;

}

RegistrationHandler class:

package cubicoder.tutorialmod;

import cubicoder.tutorialmod.init.ModBlocks;
import linky132.waywardcraft.WaywardCraft;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@EventBusSubscriber(modid = WaywardCraft.MODID)
public class RegistrationHandler {

    @SubscribeEvent
    public static void registerItems(Register<Item> event) {

        final Item[] itemBlocks = {
                new ItemBlock(ModBlocks.first_block).setRegistryName(ModBlocks.first_block.getRegistryName())

        };

        event.getRegistry().registerAll(itemBlocks);
    }

    @SubscribeEvent
    public static void registerBlocks(Register<Block> event) {
        final Block[] blocks = {
                new Block(Material.ROCK).setRegistryName(WaywardCraft.MODID, "first_block").setCreativeTab(CreativeTabs.MISC)
        };

        event.getRegistry().registerAll(blocks);
    }
}

ModelRegistrationHandler class:

package cubicoder.tutorialmod.client;

import cubicoder.tutorialmod.init.ModBlocks;
import linky132.waywardcraft.WaywardCraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;

@EventBusSubscriber(value = Side.CLIENT, modid = WaywardCraft.MODID)
public class ModelRegistrationHandler {

    @SubscribeEvent
    public static void registerModels(ModelRegistryEvent event) {
        registerModel(Item.getItemFromBlock(ModBlocks.first_block), 0);
    }

    private static void registerModel(Item item, int meta) {
        ModelLoader.setCustomModelResourceLocation(item, meta,
                new ModelResourceLocation(item.getRegistryName(), "inventory"));
    }
}

Block JSON:

{
    "textures": {
        "salt_line": "waywardcraft:blocks/salt_line"
    },
    "display": {
        "gui": {
            "rotation": [ 30, 45, 0 ],
            "translation": [ 0, 0, 0 ],
            "scale": [ 0.625, 0.625, 0.625 ]
        },
        "ground": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 0, 3, 0 ],
            "scale": [ 0.25, 0.25, 0.25 ]
        },
        "fixed": {
            "rotation": [ 0, 180, 0 ],
            "translation": [ 0, 0, 0 ],
            "scale": [ 1, 1, 1 ]
        },
        "head": {
            "rotation": [ 0, 180, 0 ],
            "translation": [ 0, 0, 0 ],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, 315, 0 ],
            "translation": [ 0, 2.5, 0 ],
            "scale": [ 0.4, 0.4, 0.4 ]
        },
        "thirdperson_righthand": {
            "rotation": [ 75, 315, 0 ],
            "translation": [ 0, 2.5, 0 ],
            "scale": [ 0.375, 0.375, 0.375 ]
        }
    },
    "elements": [
        {
            "name": "first_block",
            "from": [ 8, 0, 8 ], 
            "to": [ 8.312, 0.03, 9 ], 
            "faces": {
                "north": { "texture": "#salt_line", "uv": [ 0, 0, 14, 5 ] },
                "east": { "texture": "#salt_line", "uv": [ 0, 0, 14, 5 ] },
                "south": { "texture": "#salt_line", "uv": [ 0, 0, 14, 5 ] },
                "west": { "texture": "#salt_line", "uv": [ 0, 0, 14, 5 ] },
                "up": { "texture": "#salt_line", "uv": [ 0, 0, 16, 5 ], "rotation": 90 },
                "down": { "texture": "#salt_line", "uv": [ 0, 0, 16, 5 ] }
            }
        }
    ]
}

Block State JSON:

{
    "forge_marker": 1,
    "defaults": {
        "model": "waywardcraft:first_block"
    },
    "variants": {
        "normal": [{}],
        "inventory": [{}]
    }
}

Item JSON:

{
    "parent": "waywardcraft:block/first_block"
}

And the texture:

salt_line.png.f4949fcd7998dd41f249785fbe715677.png

Edited by Linky132
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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