Jump to content

[SOLVED][1.8.9] Block Rendering


Bektor

Recommended Posts

Hi,

 

I'm wondering how I can render a block correct. It's not just a normal block with one texture, that would be easy. :P

Lt8UmCn.png

 

Thats what I got so far.

 

My problem is now:

  • How to do the rotation? I don't want the bread texture always looking in the same direction, it should show in the direction the block is rotated, too. So when the block gets rotated the texture, too.
  • How to setup the rendering when holding the block in the hand and in the GUI?

 

The code:

Block class:

 

public class BlockHutBaker extends Block
{
    protected BlockHutBaker()
    {
        super(Material.wood);
        //setBlockName(getName());
        setUnlocalizedName(Constants.MOD_ID + "." + getName());
        setCreativeTab(ModCreativeTabs.MINECOLONIES);
        setResistance(1000f);
        GameRegistry.registerBlock(this, getName());
    }

    public String getName()
    {
        return "blockHutBaker";
    }
}

 

Blockstates json:

 

{
    "variants": {
        "normal": { "model": "minecolonies:blockHutBaker" }
    }
}

 

block json:

 

{
    "parent": "block/cube_all",
    "textures": {
        "particle": "blocks/planks_oak",
        "down": "blocks/planks_oak",
        "up": "minecolonies:blocks/blockHutBakerTop",
        "north": "minecolonies:blocks/sideChest",
        "east": "minecolonies:blocks/sideChest",
        "south": "minecolonies:blocks/sideChest",
        "west": "minecolonies:blocks/sideChest"
    }
}

 

item (or should I call it block item json :P) json:

 

{
    "parent":"minecolonies:block/blockHutBaker",
    "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 ]
        }
    }
}

 

register rendering:

 

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(ModBlocks.blockHutBaker), 0, new ModelResourceLocation(Constants.MOD_ID + ":" + ModBlocks.blockHutBaker.getRegistryName(), "inventory"));

 

 

Thx in advance.

Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

Hello, first of all you should set the rotation of the block when the block is added in the block class. Using the furnace as an example. (I added the up and down direction for you.)

 

Block class:

 

 

public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL)

public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
    {
        this.setDefaultFacing(worldIn, pos, state);
    }

    protected void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
    {
        if (!worldIn.isRemote)
        {
            Block block = worldIn.getBlockState(pos.north()).getBlock();
            Block block1 = worldIn.getBlockState(pos.south()).getBlock();
            Block block2 = worldIn.getBlockState(pos.west()).getBlock();
            Block block3 = worldIn.getBlockState(pos.east()).getBlock();
            Block block4 = worldIn.getBlockState(pos.up()).getBlock();
            Block block5 = worldIn.getBlockState(pos.down()).getBlock();
            EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

            if (enumfacing == EnumFacing.NORTH && block.isFullBlock() && !block1.isFullBlock())
            {
                enumfacing = EnumFacing.SOUTH;
            }
            else if (enumfacing == EnumFacing.SOUTH && block1.isFullBlock() && !block.isFullBlock())
            {
                enumfacing = EnumFacing.NORTH;
            }
            else if (enumfacing == EnumFacing.WEST && block2.isFullBlock() && !block3.isFullBlock())
            {
                enumfacing = EnumFacing.EAST;
            }
            else if (enumfacing == EnumFacing.EAST && block3.isFullBlock() && !block2.isFullBlock())
            {
                enumfacing = EnumFacing.WEST;
            }
            else if (enumfacing == EnumFacing.DOWN && block3.isFullBlock() && !block4.isFullBlock())
            {
                enumfacing = EnumFacing.UP;
            }
            else if (enumfacing == EnumFacing.UP && block3.isFullBlock() && !block5.isFullBlock())
            {
                enumfacing = EnumFacing.DOWN;
            }

            worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
        }
    }

 

 

 

In your blockstate you should state all variants.

 

 

	"facing=north": { "model": "pandp:washing_table" },
    "facing=south": { "model": "pandp:washing_table", "y": 180 },
    "facing=west":  { "model": "pandp:washing_table", "y": 270 },
    "facing=east":  { "model": "pandp:washing_table", "y": 90 },
    "facing=up":  { "model": "pandp:washing_table", "x": 270 },
    "facing=down":  { "model": "pandp:washing_table", "x": 90 }

 

 

 

In your blockstate you might need to do different rotations because of how you setup the model.

 

And the .json of the item of your block is in models/item is it?

 

I am not a long time veteran of modding so if you have any further problems just ask them and also if you don't understand some parts ask abotu what they do instead of blindly copying. (Not saying that you do just to make sure.  :))

 

Link to comment
Share on other sites

    protected BlockHutBaker()
    {
        super(Material.wood);
        //setBlockName(getName());
        setUnlocalizedName(Constants.MOD_ID + "." + getName());
        setCreativeTab(ModCreativeTabs.MINECOLONIES);
        
        setResistance(1000f);
        GameRegistry.registerBlock(this, getName());
        
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
    }

 

Oh and here is the Inventory rendering stuff called:

    @Mod.EventHandler
    public void init(FMLInitializationEvent event)
    {
    	proxy.registerRendering();
    }

The code with the model mesher itself is in the client proxy in the metod which is called above.

Developer of Primeval Forest.

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 there! I am trying to make custom dimensions for a modpack I am making in an older minecraft version, 1.16.5. I like that version and it has a few other mods that have not been updated that I would still like to use. Anyway, I am having a terrible time with getting my dimension to work and have tried using code from other peoples projects to at least figure out what I'm supposed to be doing but it has not been as helpful as I would have liked. If anyone could help that would be greatly appreciated! Here is my github with all the code as I am using it: https://github.com/BladeColdsteel/InvigoratedDimensionsMod I have also included the last log, https://pastebin.com/zX9vsDSq, I had when I tried to load up a world, let me know if there is anything else I should send though, thank you!
    • Whether you are a fan of Hypixel Bedwars, SkyWars and PvP gamemodes like that, well you would enjoy this server! We have a very fun and unique style of PvP that a lot of our players really enjoy and we want to bring this server to more players like you! Yes you reading this post haha. Introducing, the Minezone Network, home of SUPER CRAFT BLOCKS. We've been working on this server for over 4 years now. Here is what we have to offer: SUPER CRAFT BLOCKS: This has 3 different gamemodes you can play, Classic, Duels and Frenzy. Each mode offers over 60 kits to choose from, along with a total of over 60 maps, allowing for various different playstyles on each map. There are also random powerups that spawn on the map which can include Health Pots, Bazookas, Nukes, Extra Lives and way way more! There is also double jump in this gamemode as well, which makes PvP a lot more fun & unique. You only need a minimum of 2 players to start any mode! Classic: Choose a kit, 5 lives for each player, fight it out and claim the #1 spot! Look out for lightning as they can spawn powerups to really give you an advantage in the game! Duels: Fight against another random player or one of your friends and see who is the best! Frenzy: Your kit is randomly selected for you, each life you will have a different kit. You can fight with up to 100 players in this mode and lets see who will be the best out of that 100! All the other stuff from Classic/Duels apply to this mode as well like powerups. We have 2 ranks on this server too, VIP and CAPTAIN which has a bunch of different perks for SCB and other things like Cosmetics and more.   SERVER IP: If this server has caught your interest in any way, please consider joining and you will NOT regret it! Bring some of your friends online for an even better experience and join in on the fun at: IP: minezone.club Hope to see you online!   SERVER TRAILER: https://www.youtube.com/watch?v=0phpMgu1mH0
    • The mod give new blocks  
    • I will a Mode for 1.21 in this Mod give new block, items and dimensions   
  • Topics

×
×
  • Create New...

Important Information

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