Jump to content

Can't set name of planks correctly


Jack4096

Recommended Posts

I am trying to set the name of the planks, but I have no idea even after studying the code for hours, how to even add the names of the blocks. Their name is just "planks" but I WANT to concatenate String "planks" with the planks' enum's assigned name, to add an "_", and then add the name of the enum of the plank. Please ask for additional information if my problem seems unclear, and there are no crashes or error messages:

 

public class MagicPlank extends Block implements IHasModel
{
    public static final PropertyEnum<MagicPlank.EnumType> VARIANT = PropertyEnum.<MagicPlank.EnumType>create("variant", MagicPlank.EnumType.class);

    public MagicPlank(String name, Material material)
    {
    	super(material);
    	
    	setUnlocalizedName(name);
        setRegistryName(name);
        
        ModBlocks.BLOCKS.add(this);
		ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
        
        this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
        this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, MagicPlank.EnumType.MAGIC));
    }

    /**
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
     * returns the metadata of the dropped item based on the old metadata of the block.
     */
    public int damageDropped(IBlockState state)
    {
        return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMetadata();
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
    {
        for (MagicPlank.EnumType magicplank$enumtype : MagicPlank.EnumType.values())
        {
            items.add(new ItemStack(this, 1, magicplank$enumtype.getMetadata()));
        }
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(VARIANT, MagicPlank.EnumType.byMetadata(meta));
    }

    /**
     * Get the MapColor for this Block and the given BlockState
     */
    public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMapColor();
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMetadata();
    }
    
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {VARIANT});
    }

    public static enum EnumType implements IStringSerializable
    {
        MAGIC(0, "magic", MapColor.SAND),
    	MAPLE(1, "maple", MapColor.SAND),
    	REDWOOD(2, "redwood", MapColor.SAND),
    	YEW(3, "yew", MapColor.SAND);
        
        private static final MagicPlank.EnumType[] META_LOOKUP = new MagicPlank.EnumType[values().length];
        private final int meta;
        private final String name;
        private final String unlocalizedName;
        /** The color that represents this entry on a map. */
        private final MapColor mapColor;

        private EnumType(int metaIn, String nameIn, MapColor mapColorIn)
        {
            this(metaIn, nameIn, nameIn, mapColorIn);
        }

        private EnumType(int metaIn, String nameIn, String unlocalizedNameIn, MapColor mapColorIn)
        {
            this.meta = metaIn;
            this.name = nameIn;
            this.unlocalizedName = unlocalizedNameIn;
            this.mapColor = mapColorIn;
        }

        public int getMetadata()
        {
            return this.meta;
        }

        /**
         * The color which represents this entry on a map.
         */
        public MapColor getMapColor()
        {
            return this.mapColor;
        }

        public String toString()
        {
            return this.name;
        }

        public static MagicPlank.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.unlocalizedName;
        }

        static
        {
            for (MagicPlank.EnumType magicplank$enumtype : values())
            {
                META_LOOKUP[magicplank$enumtype.getMetadata()] = magicplank$enumtype;
            }
        }
        
    }
    
    @Override
    public void registerModels() {
        Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
    }
    
}

 

Link to comment
Share on other sites

15 minutes ago, Jack4096 said:

WANT to concatenate String "planks" with the planks' enum's assigned name, to add an "_", and then add the name of the enum of the plank.

Override getUnlocalizedName(ItemStack) and base it off of the metadata. Then you will have to put multiple entries into your lang file.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

7 minutes ago, Animefan8888 said:

Override getUnlocalizedName(ItemStack) and base it off of the metadata. Then you will have to put multiple entries into your lang file.

I tried to figure out how to do that, and I couldn't figure out how. Could you please explain?

Link to comment
Share on other sites

1 minute ago, Jack4096 said:

I tried to figure out how to do that, and I couldn't figure out how. Could you please explain?

You will need a custom ItemBlock implementation which I assume you have because your block has metadata. There is where you will override the method I said above.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

18 hours ago, Jack4096 said:

implements IHasModel

Don’t use IHasModel or anything like it. All items have models and it leads to you writing code over and over again when you could just solve the entire problem in 3 lines of code.

for(Item item: ModItems) {

  ModelLoader.setCustomModelLocation(item, meta, model location);

}

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

On 10/12/2018 at 6:01 PM, Cadiboo said:

Don’t use IHasModel or anything like it. All items have models and it leads to you writing code over and over again when you could just solve the entire problem in 3 lines of code.

for(Item item: ModItems) {

  ModelLoader.setCustomModelLocation(item, meta, model location);

}

I tried to figure out where to put this code, but I couldn't figure it out, could you explain? Please. Also, what exactly would I put for "item" and "model location"?

Edited by Jack4096
Link to comment
Share on other sites

7 minutes ago, Jack4096 said:

what exactly would I put for "item" and "model location"?

You don't have to put anything for "item" since it is a variable already, look at the example provided.

As for "model location" you would put something like

new ModelResourceLocation(item.getRegistryName(), "inventory");

 

8 minutes ago, Jack4096 said:

where to put this code

In your ModelRegistryEvent.

Link to comment
Share on other sites

On 10/14/2018 at 8:53 AM, V0idWa1k3r said:

You don't have to put anything for "item" since it is a variable already, look at the example provided.

As for "model location" you would put something like


new ModelResourceLocation(item.getRegistryName(), "inventory");

 

In your ModelRegistryEvent.

Honestly I have no idea how to write any of the code you guys are suggesting... I have no idea how. Could you guys just help with setting proper names for each plank in the enum? For all 4 plank types? For Magic, Maple, Redwood, and Yew?

Edited by Jack4096
Was changing the question
Link to comment
Share on other sites

put this code

for(Item item: allYourItems) {
	ModelLoader.setCustomModelResourceLocation(item, itemMeta, new ModelResourceLocation(new ResourceLocation(registryNameResourceNamespace, registryNameResourcePath), "normal"));
}

In your ModelRegistryEvent. https://mcforge.readthedocs.io/en/latest/concepts/registries/#registering-things like this

//inside your event subscriber
(@Mod.EventBusSubscriber(value=Side.CLIENT))
public class ClientEventSubscriber {
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public (static) void onRegisterModelsEvent(final ModelRegistryEvent event) {
		//model registration code goes here
	}
}

 

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

54 minutes ago, Jack4096 said:

Could you guys just help with setting proper names for each plank in the enum? For all 4 plank types? For Magic, Maple, Redwood, and Yew?

 

On 10/11/2018 at 9:34 PM, Animefan8888 said:

You will need a custom ItemBlock implementation which I assume you have because your block has metadata. There is where you will override the method I said above.

 

On 10/11/2018 at 9:24 PM, Animefan8888 said:

Override getUnlocalizedName(ItemStack) and base it off of the metadata. Then you will have to put multiple entries into your lang file.

I did already.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Can I reccomend not using metadata? In 1.13 the flattening is happening and all the different types of wood are moving to different blocks (this doesn't mean different classes). 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

30 minutes ago, Cadiboo said:

Can I reccomend not using metadata?

Of course.

31 minutes ago, Cadiboo said:

In 1.13 the flattening is happening and all the different types of wood are moving to different blocks (this doesn't mean different classes). 

But going by this logic he shouldn't be developing at all, because 1.13 isnt out yet. Because there would be no point in releasing the mod for 1.12 if it uses too many block ids.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

13 minutes ago, Animefan8888 said:

Of course.

But going by this logic he shouldn't be developing at all, because 1.13 isnt out yet. Because there would be no point in releasing the mod for 1.12 if it uses too many block ids.

I think using 4 ids with an axis variant is better that using 1 id and squeezing 4 variants and the axis into 1 block. To be fair you only need 2 bits for the variant and 1 and a half (2) bits for the axis if your being efficient, still thats your 4 bits used up with space for only 1 more axis/variant.

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

2 minutes ago, Cadiboo said:

I think using 4 ids with an axis variant is better that using 1 id and squeezing 4 variants and the axis into 1 block. To be fair you only need 2 bits for the variant and 1 and a half (2) bits for the axis if your being efficient, still thats your 4 bits used up with space for only 1 more axis/variant.

 

On 10/11/2018 at 9:07 PM, Jack4096 said:

planks

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Well, that does change the context a bit.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

34 minutes ago, Cadiboo said:

Well, that does change the context a bit.

Also, you technically only have to use 12 of the sixteen values you have with metadata to store 4 logs. Therefore you could store 5 logs into one block.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, Cadiboo said:

with space for only 1 more axis/variant

 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

2 hours ago, Cadiboo said:

only need 2 bits for the variant and 1 and a half (2) bits

The thing is, you cant break the bits up like this. Its non sensical. You have four bits(16 values) if you split the bits up like you said then you have 2 bits or four values to store the variant(oak, birch, etc) and then the other 2 bits for the axis where you only use 3 values out of four. Of which you couldn't use as another variant because then you would lose your axis. So instead it is better to express it in numerical values. Whether it's in base 10, 16, or 2.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

3 hours ago, Cadiboo said:

Can I reccomend not using metadata? In 1.13 the flattening is happening and all the different types of wood are moving to different blocks (this doesn't mean different classes). 

In that case, I will most likely just wait for 1.13 then.

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.



×
×
  • Create New...

Important Information

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