Jump to content

Recommended Posts

Posted

Not sure which of the titles options is actually my problem, but here the problem is:

 

I have a general blockslab class with two variants:

 

The slabs place and appear correctly in the game world as blocks/slabs.

 

However, as inventory and entity items they are untextured (but correctly named).

 

There's an additional error where the game says it cant find the approprite blockstates for an item baring the name the itemBlock is registered with. (i'm assuming this is where the issue is occuring). This currently removed by using the string "mossy_slab" to register the itemblock. note this has no impact on the ingame issue.

 

My blockstate and model files are copy pastes and so contain no information about inventory or ground states. These seems a potentional solution.

 

The blockSlab class (i'm fairly confident this is in order):

 

 

 

public class mossySlab extends BlockSlab

{

    public static final PropertyEnum<mossySlab.EnumType> VARIANT = PropertyEnum.<mossySlab.EnumType>create("variant", mossySlab.EnumType.class);

 

 

public mossySlab() {

 

super(Material.ROCK);

this.setHardness(2.0F);

this.setResistance(10F);

//this.fullblock = fullblock;

this.setSoundType(SoundType.STONE);

        IBlockState iblockstate = this.blockState.getBaseState();

 

        if (!this.isDouble())

      {

        this.setCreativeTab(w2theJungle.JungleModTab);

this.setLightOpacity(0);

            iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);

        }

 

this.setDefaultState(iblockstate.withProperty(VARIANT, mossySlab.EnumType.MOSSY_SLAB));

}

 

@SideOnly(Side.CLIENT)

@Override

public ItemStack getPickBlock(IBlockState state, RayTraceResult trace, World wrld, BlockPos pos, EntityPlayer player)

{

        return new ItemStack(JungleBlocks.mossyslabSingle, 1, ((mossySlab.EnumType)state.getValue(VARIANT)).getMetadata());

 

}

 

    public int quantityDropped(Random p_149745_1_)

    {

        return this.isDouble() ? 2 : 1;

    }

   

    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)

    {

        return new ItemStack(Blocks.STONE_SLAB, 1, ((mossySlab.EnumType)state.getValue(VARIANT)).getMetadata());

    }

   

@Override

public Item getItemDropped(IBlockState state, Random random, int b) {

 

        return Item.getItemFromBlock(JungleBlocks.mossyslabSingle);

}

   

    public IBlockState getStateFromMeta(int meta)

    {

        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, mossySlab.EnumType.byMetadata(meta & 7));

 

        if (!this.isDouble())

        {

            iblockstate = iblockstate.withProperty(HALF, (meta & 8) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);

        }

 

        return iblockstate;

    }

   

    public int getMetaFromState(IBlockState state)

    {

        int i = 0;

        i = i | ((mossySlab.EnumType)state.getValue(VARIANT)).getMetadata();

 

        if (!this.isDouble() && state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)

        {

            i |= 8;

        }

 

        return i;

    }

 

@Override

public String getUnlocalizedName(int meta) {

        return super.getUnlocalizedName() + "." + mossySlab.EnumType.byMetadata(meta).getUnlocalizedName();

}

   

@Override

public Comparable<?> getTypeForItem(ItemStack stack) {

        return mossySlab.EnumType.byMetadata(stack.getMetadata() & 7);

}

 

@Override

public IProperty<?> getVariantProperty() {

        return VARIANT;

}

 

    @SideOnly(Side.CLIENT)

    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)

    {

        if (itemIn != Item.getItemFromBlock(JungleBlocks.mossyslabDouble))

        {

            for (mossySlab.EnumType blockstoneslab$enumtype : mossySlab.EnumType.values())

            {

            list.add(new ItemStack(itemIn, 1, blockstoneslab$enumtype.getMetadata()));

            }

        }

    }

 

    public int damageDropped(IBlockState state)

    {

        return ((mossySlab.EnumType)state.getValue(VARIANT)).getMetadata();

    }

 

    protected final BlockStateContainer createBlockState() {

        if (this.isDouble()) {

            return new BlockStateContainer(this, new IProperty[] {VARIANT});

        } else {

            return new BlockStateContainer(

                this,

                new IProperty[] {HALF, VARIANT});

        }

    }

   

    public MapColor getMapColor(IBlockState state)

    {

        return ((mossySlab.EnumType)state.getValue(VARIANT)).getMapColor();

    }

   

@Override

public boolean isDouble() {

return false;

}

 

    public static class Double extends mossySlab

    {

        public boolean isDouble()

        {

            return true;

        }

    }

 

    public static class Half extends mossySlab

    {

        public boolean isDouble()

        {

            return false;

        }

    }

 

 

    public static enum EnumType implements IStringSerializable

    {

        MOSSY_SLAB(0, "mossy", MapColor.STONE),

        MOSSY_SMOOTH_SLAB(1, "mossy_smooth", MapColor.STONE);

 

 

        private static final mossySlab.EnumType[] META_LOOKUP = new mossySlab.EnumType[values().length];

        private final int meta;

        private final String name;

        private final MapColor mapColor;

 

        private EnumType(int p_i46391_3_, String p_i46391_4_, MapColor p_i46391_5_)

        {

            this.meta = p_i46391_3_;

            this.name = p_i46391_4_;

            this.mapColor = p_i46391_5_;

        }

 

        public int getMetadata()

        {

            return this.meta;

        }

 

        public MapColor getMapColor()

        {

            return this.mapColor;

        }

 

        public String toString()

        {

            return this.name;

        }

 

        public static mossySlab.EnumType byMetadata(int meta)

        {

            if (meta < 0 || meta >= META_LOOKUP.length)

            {

                meta = 0;

            }

 

            return META_LOOKUP[meta];

        }

 

        public String getName()

        {

            return this.name;

        }

 

        public String getUnlocalizedName()

        {

            return this.name;

        }

 

        static

        {

            for (mossySlab.EnumType blockstoneslabnew$enumtype : values())

            {

                META_LOOKUP[blockstoneslabnew$enumtype.getMetadata()] = blockstoneslabnew$enumtype;

            }

        }

    }

}

 

 

 

The definition and registration:

 

 

 

 

                mossyslabSingle = (BlockSlab) (new mossySlab.Half()).setUnlocalizedName("stoneMossySlab");

mossyslabDouble = (BlockSlab) (new mossySlab.Double()).setUnlocalizedName("stoneMossySlab");

 

 

                ItemSlab item = (ItemSlab) (new ItemSlab(JungleBlocks.mossyslabSingle, JungleBlocks.mossyslabSingle, JungleBlocks.mossyslabDouble)).setUnlocalizedName("mossySlab");

registerBlockSlab(mossyslabSingle, item, "mossy_slab"); 

        registerBlockSlab(mossyslabDouble, null, "mossy_double_slab");

 

public static void registerBlockSlab(Block block, ItemSlab item, String string)

{

block.setRegistryName(string);

GameRegistry.register(block);

if(item != null)

{

GameRegistry.register(item, block.getRegistryName());

}

       

}

 

ModelLoader.setCustomStateMapper(mossyslabSingle, (new StateMap.Builder()).withName(mossySlab.VARIANT).withSuffix("_slab").build());

                ModelLoader.setCustomStateMapper(mossyslabDouble, (new StateMap.Builder()).withName(mossySlab.VARIANT).withSuffix("_double_slab").build());

 

 

 

 

The render:

 

 

 

                registerSlabRender("mossy_slab", mossySlab.EnumType.MOSSY_SLAB.getMetadata(), JungleBlocks.mossyslabSingle);

registerSlabRender("mossy_smooth_slab", mossySlab.EnumType.MOSSY_SMOOTH_SLAB.getMetadata(), JungleBlocks.mossyslabSingle);

 

public static void registerSlabRender(String string, int i, Block block)

{

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), i, new ModelResourceLocation(string, "inventory"));

}

 

 

 

edit: to remove commented out experiments/notes/old code

Posted

Where and when do you call your rendering-registration? Main, proxy, preInit, init, postInit?

 

Also, do not use Minecraft.getMinecraft().getRenderItem().getItemModelMesher(), use ModelLoader.setCustomModelResourceLocation instead, and be sure to call that in preInit.

Example would be, (by passing block)

ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

ta. problem solved. the original call was in the init event: the itemmeshers would crash the game if put in preinit. moot now, since i switched t the model loaders which have to be put in preinit. one thing to note, the string below had to have the modid added to completely cure the problem.

 

  public static void registerSlabRender(String string, int i, Block block)

  {

        //ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), i, new ModelResourceLocation("thejungle:" + string, "inventory"));

 

  }

Posted

ta. problem solved. the original call was in the init event: the itemmeshers would crash the game if put in preinit. moot now, since i switched t the model loaders which have to be put in preinit. one thing to note, the string below had to have the modid added to completely cure the problem.

 

  public static void registerSlabRender(String string, int i, Block block)

  {

        //ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), i, new ModelResourceLocation("thejungle:" + string, "inventory"));

 

  }

 

To quote the Block#setRegistryName documentation:

/**

    * Sets a unique name for this Item. This should be used for uniquely identify the instance of the Item.

    * This is the valid replacement for the atrocious 'getUnlocalizedName().substring(6)' stuff that everyone does.

    * Unlocalized names have NOTHING to do with unique identifiers. As demonstrated by vanilla blocks and items.

    *

    * The supplied name will be prefixed with the currently active mod's modId.

    * If the supplied name already has a prefix that is different, it will be used and a warning will be logged.

    *

    * If a name already exists, or this Item is already registered in a registry, then an IllegalStateException is thrown.

    *

    * Returns 'this' to allow for chaining.

    *

    * @param name Unique registry name

    * @return This instance

    */

Same thing applies to, random strings. You are meant to use RegistryName here, but you imitate it using a string that does what RegistryName does.

It's unlikely, but if ANY mod, literally any ever has a method that checks blocks, and uses Block#getRegistryName, on this block, guess what'll happen. Bam, nullpointerexception.

Sorry if I sound harsh, but this is what you are meant to use! It's actually dangerous to do what you are doing now.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

EDIT: having dwelt on the below, i have to ask if you're sure about the registryname in this instance. the slab variants dont have registry names. in anycase at this point the game just wants the name of the blockstate file. calling the registry name is highly convenient, but not essential. the blockstate file doesnt have to have the registry name, the two simply have to match.

 

EDIT: there are two seperate render calls one for each slab variant. its the passed in block that doesnt change.

 

the code was largely created by scouring the vanilla stuff, which uses a string. i say this merely by way of explaining it. i had looked at it after making the changes you suggested above and thought that it seemed identical to the registry name. but theres a snag here. changing the string to block.getregistryname, while not throwing up errors, gives both slabs the same texture in inventory and as an entity item. this is particularly odd as the passed in string does not change, the line in the post above is called only once.

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.