Jump to content

(1.11)(SOLVED)ItemBlock Models Acting Strangely


Bernasss12

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

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

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

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



×
×
  • Create New...

Important Information

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