Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

(1.11)(SOLVED)ItemBlock Models Acting Strangely


Bernasss12
 Share

Recommended Posts

Hello, I'm new to modding and know just a little bit of Java but while making a mod just to learn the basics I stumbled across a problem I can´t really understand.

 

I'm using the same ModBlock class for every block on my mod, they are basic blocks (Iron, Gold, Diamond and Emerald Blocks for their Blazed versions) and while everything works great with the Iron Block, the others don't seem to have a ItemBlock model. This was working fine on 1.10.2 but now  in 1.11 this happens.

 

System:

 

-- System Details --

Details:

Minecraft Version: 1.11

Operating System: Windows 8 (amd64) version 6.2

Java Version: 1.8.0_112, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 264617312 bytes (252 MB) / 981991424 bytes (936 MB) up to 1886912512 bytes (1799 MB)

JVM Flags: 0 total;

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP 9.35 Powered by Forge 13.19.1.2189 4 mods loaded, 4 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCHIJAAAA mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)

UCHIJAAAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.11-13.19.1.2189.jar)

UCHIJAAAA forge{13.19.1.2189} [Minecraft Forge] (forgeSrc-1.11-13.19.1.2189.jar)

UCHIJAAAA pbtmod{0.1} [+Blaze Tools Mod] (PlusBlazeToolsMod_main)

Loaded coremods (and transformers):

GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 375.95' Renderer: 'GeForce GTX 750 Ti/PCIe/SSE2'

Launched Version: 1.11

LWJGL: 2.9.4

OpenGL: GeForce GTX 750 Ti/PCIe/SSE2 GL version 4.5.0 NVIDIA 375.95, NVIDIA Corporation

GL Caps: Using GL 1.3 multitexturing.

Using GL 1.3 texture combiners.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Shaders are available because OpenGL 2.1 is supported.

VBOs are available because OpenGL 1.5 is supported.

 

Using VBOs: Yes

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs:

Current Language: English (US)

Profiler Position: N/A (disabled)

CPU: 8x AMD FX-8320 Eight-Core Processor

 

 

(https://github.com/Bernasss12/PlusBlazeToolsMod/tree/master/src/main/java/com/bernasss12/pbtmod/block)

 

ModBlock (extends Block):

package com.bernasss12.pbtmod.block;

import com.bernasss12.pbtmod.PlusBlazeToolsMain;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

/**
* Created by Bernardo on 30/11/2016.
*/
public class ModBlock extends Block
{
    protected String name;
    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

    public ModBlock(Material material, String unlocalizedName, String textureName) {
        super(material);
        this.name = textureName;
        setUnlocalizedName(unlocalizedName);
        setRegistryName(name);
        setHardness(3.0F);
        setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
    }

    public void registerItemModel(ItemBlock itemBlock) {
        PlusBlazeToolsMain.proxy.registerItemRenderer(itemBlock, 0, name);
    }

    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[]{FACING});
    }

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

    private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
    {
        if (!worldIn.isRemote)
        {
            IBlockState iblockstate = worldIn.getBlockState(pos.north());
            IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
            IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
            IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
            EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

            if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
            {
                enumfacing = EnumFacing.SOUTH;
            }
            else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
            {
                enumfacing = EnumFacing.NORTH;
            }
            else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
            {
                enumfacing = EnumFacing.EAST;
            }
            else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
            {
                enumfacing = EnumFacing.WEST;
            }

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

    public int getMetaFromState(IBlockState state)
    {
        return ((EnumFacing)state.getValue(FACING)).getIndex();
    }



    public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand)
    {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }

    @Override
    public ModBlock setCreativeTab(CreativeTabs tab) {
        super.setCreativeTab(tab);
        return this;
    }

    @Override
    public ModBlock setLightOpacity(int opacity) {
        super.setLightOpacity(opacity);
        return this;
    }

    @Override
    public ModBlock setLightLevel(float value) {
        super.setLightLevel(value);
        return this;
    }

    @Override
    public ModBlock setResistance(float resistance) {
        super.setResistance(resistance);
        return this;
    }

}

 

ModBlocks (registers everything):

package com.bernasss12.pbtmod.block;

import com.bernasss12.pbtmod.PlusBlazeToolsMain;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.fml.common.registry.GameRegistry;

/**
* Created by Bernardo on 06/12/2016.
*/
public class ModBlocks {

    /** Creating variable to every block. */

    public static ModBlock blazedGoldBlock;
    public static ModBlock blazedDiamondBlock;
    public static ModBlock blazedEmeraldBlock;
    public static ModBlock blazedIronBlock;

    public static void preInit(){

        /** Registering every block. */

        blazedGoldBlock = register(new ModBlock(Material.IRON, "blazedGoldBlock", "blazed_gold_block").setCreativeTab(PlusBlazeToolsMain.tabGeneral).setLightLevel(7.5F));
        blazedDiamondBlock = register(new ModBlock(Material.IRON, "blazedDiamondBlock", "blazed_diamond_block").setCreativeTab(PlusBlazeToolsMain.tabGeneral).setLightLevel(11.25F));
        blazedEmeraldBlock = register(new ModBlock(Material.IRON, "blazedEmeraldBlock", "blazed_emerald_block").setCreativeTab(PlusBlazeToolsMain.tabGeneral).setLightLevel(15F));
        blazedIronBlock = register(new ModBlock(Material.IRON, "blazedIronBlock", "blazed_iron_block").setCreativeTab(PlusBlazeToolsMain.tabGeneral).setLightLevel(3.75F));
    }

    private static <T extends Block> T register(T block, ItemBlock itemBlock) {
        GameRegistry.register(block);
        GameRegistry.register(itemBlock);

        if (block instanceof ModBlock) {
            ((ModBlock)block).registerItemModel(itemBlock);
        }

        return block;
    }

    private static <T extends Block> T register(T block) {
        ItemBlock itemBlock = new ItemBlock(block);
        itemBlock.setRegistryName(block.getRegistryName());
        return register(block, itemBlock);
    }

}

 

Images:

 

 

 

The code is heavily influenced by wehavecookies YouTube tutorials, ShadowFact's web tutorials, TheGreyGhost's Minecraft By Example and more.

 

Hope you can help.

 

Link to comment
Share on other sites

For situations like this, Minecraft should log an error loading the model/texture. Please provide that info.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I have the same problem with all "special" blocks. By special I mean that they either have two or more textures on the sides, it is directional, or it has a custom model.

YouTube:

https://www.youtube.com/channel/UCaK5oRw4yd7PurBWww9tVhA

Kuribo64 (where I am most active):

http://kuribo64.net/board/profile.php?id=1423

 

Thanks for your answer!

 

Current projects:

 

3D Geometry Dash: 13%

Terracraft (MC Mod): 8%

New Super Kaizo Bros DS: 100% (no download for now :'( )

New Super Kaizo Bros. Wii: 12%

Super Mario Galaxy 1.5: 96%

New Super Mario Bros Galaxy: 85%

Kerbal Space Program Advance: 47%

MC CREATE: 20%

Mystery Projects: 10%, 40%, 13%, and 94%

Link to comment
Share on other sites

Did you make any blocks that have more than one different texture? Have you got the ItemBlocks working? What about custom rendered blocks? Did you get those working? The only ItemBlock models that I can get working is those for a block that only has one texture. If you can get those working, please post the code, I really need it. FYI I get: the model variant for fast_cooker#inventory could not be loaded. I can't tell you exactly because I don't have my PC with me right now.

YouTube:

https://www.youtube.com/channel/UCaK5oRw4yd7PurBWww9tVhA

Kuribo64 (where I am most active):

http://kuribo64.net/board/profile.php?id=1423

 

Thanks for your answer!

 

Current projects:

 

3D Geometry Dash: 13%

Terracraft (MC Mod): 8%

New Super Kaizo Bros DS: 100% (no download for now :'( )

New Super Kaizo Bros. Wii: 12%

Super Mario Galaxy 1.5: 96%

New Super Mario Bros Galaxy: 85%

Kerbal Space Program Advance: 47%

MC CREATE: 20%

Mystery Projects: 10%, 40%, 13%, and 94%

Link to comment
Share on other sites

Yes, the blocks i have right now all have 3 different textures, just like the vannila furnace, pumpkin, dispenser, dropper etc. You could probably just go take a look on the code but here's what i think makes it work:

 

BaseBlock class must have (in my case):

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

This is a direct copy of the vannila classes but basically this makes the direction only include north, south, east and west, not having up or down.

 

Then in the BaseBlock constructor you must have a default "facing" state (I believe this only affects the block while it is not placed in the world):

setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));

Vanilla mc uses North for example.

 

The other things I have on that same class are:

public void registerItemModel(ItemBlock itemBlock) 
    {
        PlusBlazeToolsMain.proxy.registerItemRenderer(itemBlock, 0, name);
    }

protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[]{FACING});
    }

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

private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
    {
        if (!worldIn.isRemote)
        {
            IBlockState iblockstate = worldIn.getBlockState(pos.north());
            IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
            IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
            IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
            EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

            if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
            {
                enumfacing = EnumFacing.SOUTH;
            }
            else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
            {
                enumfacing = EnumFacing.NORTH;
            }
            else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
            {
                enumfacing = EnumFacing.EAST;
            }
            else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
            {
                enumfacing = EnumFacing.WEST;
            }

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

public int getMetaFromState(IBlockState state)
    {
        return ((EnumFacing)state.getValue(FACING)).getIndex();
    }



    public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand)
    {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }

I'm sure im not the best to explain but I understand most of it. Go check the proxys and stuff i have on my repo so i dont have to say everything.

But in general:

  • registerItemModel() will register the inventory icon of your block, it is a model file that can be however you like (block or item). I made it just like the block when placed.
  • createBlockState() will create the block state based on the property you created.
  • onBlockAdded() in this case is used to change the default state of the your property to your real world use in this case based on: setDefaultFacing()
  • setDefaultFacing() will return the direction the player is currently facing, im not sure how this works bc it's a direct copy from vanila and I still haven´t really thought about it.
  • getStateForPlacement() will get the direction of the player and make the block be placed facing the opposite direction, you can change it acconding to your needs by just not using .getOpposite().0
  • getMetaFromState() the game will ask for it, just copy it and use it.

 

The files you need in your assets:

 

assets/modid/blockstates/yourblock_registry_name.json

{
"variants": {
	"facing=north": { "model": "modid:yourblock_registry_name_normal" },
                "facing=east":  { "model": "modid:yourblock_registry_name_normal", "y": 90 }
	"facing=south": { "model": "modid:yourblock_registry_name_normal", "y": 180 },
	"facing=west":  { "model": "modid:yourblock_registry_name_normal", "y": 270 },

}
}

 

assets/modid/models/block/yourblock_registry_name_normal.json

{
"parent": "block/orientable",
"textures": {
	"top": "modid:blocks/yourblock_texturename_top",
	"front": "modid:blocks/yourblock_texturename_front",
	"side": "modid:blocks/yourblock_texturename_side"
}
}

I used the vanilla parent block/orientable bc i dont reall need forge's json complexity, i think this is easier.

 

assets/modid/models/item/yourblock_registry_name.json

{
"parent": "yourblock_registry_name_normal",
"display": {
	"thirdperson": {
		"rotation": [ 10, -45, 170],
		"translation": [ 0, 1.5, -2.75],
		"scale": [ 0.375, 0.375, 0.375]
	}
}
}

 

I don't have much experience, I rely heavily on vanilla code and tutorials but i like to try things out until they work.

I hope this was useful or that at least you understood something from this. Good luck!

 

 

Link to comment
Share on other sites

I think my problem is with my ItemModel, maybe my parent is incorrect? I have the parent as "parent":"momod:fast_cooker"

momod is my MODID, fast_cooker is the block's name. I don't have my PC right now, so I can't be sure. Another problem I have with the Fast Cooker is that the tile entity seems to be acting strangely. For example, I get an error on the console saying that the tile entity com.thesuncat.momod.tileentity.TileEntityFastCooker.class is missing a mapping. When you break the fast cooker, it does not drop anything, and breaks instantly. When you do that, the space where the fast cooker was gets really buggy. You can't collide with it, the screen will just vibrate and you'll see your coordinates going from (example) 33.18 to 33.22 and then 33.18 really fast. If you place a block there, the block will appear shortly and then turn into a fast cooker, and your stack size will not decrease. Then, when you destroy the fast cooker, it will break instantly and won't drop anything, but the place where it was will become accessible, and stop being buggy. Another problem is that when you smelt something, there is a random chance the progress bars will not update at all, or that you item will smelt, just that it will be unsmelted in the input slot, and smelted in the output slot. The item model is purple and black. What does work is that it is directional, right clickable, and smelts stuff. It sometimes shows the progress bars. I have even tried copypasta the vanilla furnace code, but it will give me the exact same results. Another problem is that the fast cooker has no use at all. When I had it in the 1.7.10 version of my mod, it cooked 7 times faster than a regular furnace, but just changing the furnace speed and total cook time variables does not work. How would I go about making this furnace faster than the normal furnace? The major problem I have is with the tile entity bugs and the ItemBlock model problem. Could anyone help me? It was working in 1.7.10...

YouTube:

https://www.youtube.com/channel/UCaK5oRw4yd7PurBWww9tVhA

Kuribo64 (where I am most active):

http://kuribo64.net/board/profile.php?id=1423

 

Thanks for your answer!

 

Current projects:

 

3D Geometry Dash: 13%

Terracraft (MC Mod): 8%

New Super Kaizo Bros DS: 100% (no download for now :'( )

New Super Kaizo Bros. Wii: 12%

Super Mario Galaxy 1.5: 96%

New Super Mario Bros Galaxy: 85%

Kerbal Space Program Advance: 47%

MC CREATE: 20%

Mystery Projects: 10%, 40%, 13%, and 94%

Link to comment
Share on other sites

When you break the fast cooker, it does not drop anything, and breaks instantly.

Well, maybe you forgot to set a hardness value, and when you do that, if the material you chose is something that needs a pick to drop the block that behavior could happen and the bugginess if for some odd reason the block was only being destroyed on the client side. Tbh haven´t done anything related to tile entities so I can´t help you with it.

Link to comment
Share on other sites

What about the ItemModel? That is the problem I am focusing on right now.

YouTube:

https://www.youtube.com/channel/UCaK5oRw4yd7PurBWww9tVhA

Kuribo64 (where I am most active):

http://kuribo64.net/board/profile.php?id=1423

 

Thanks for your answer!

 

Current projects:

 

3D Geometry Dash: 13%

Terracraft (MC Mod): 8%

New Super Kaizo Bros DS: 100% (no download for now :'( )

New Super Kaizo Bros. Wii: 12%

Super Mario Galaxy 1.5: 96%

New Super Mario Bros Galaxy: 85%

Kerbal Space Program Advance: 47%

MC CREATE: 20%

Mystery Projects: 10%, 40%, 13%, and 94%

Link to comment
Share on other sites

I got everything fixed but the ItemModel... I tried to do

"parent": "fast_cooker" 

and I got the same result... Anyone know what is wrong?

YouTube:

https://www.youtube.com/channel/UCaK5oRw4yd7PurBWww9tVhA

Kuribo64 (where I am most active):

http://kuribo64.net/board/profile.php?id=1423

 

Thanks for your answer!

 

Current projects:

 

3D Geometry Dash: 13%

Terracraft (MC Mod): 8%

New Super Kaizo Bros DS: 100% (no download for now :'( )

New Super Kaizo Bros. Wii: 12%

Super Mario Galaxy 1.5: 96%

New Super Mario Bros Galaxy: 85%

Kerbal Space Program Advance: 47%

MC CREATE: 20%

Mystery Projects: 10%, 40%, 13%, and 94%

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.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.