Posted August 31, 20196 yr Hi there! I've started my own mod and after following a couple of forum posts, tutorials and looking at the vanilla code of the BlockPlanks, BlockLogs, (etc)... I was able to create my own trees and generate them all around but now I'm having a very specific problem. I want my custom planks to have the same functionalities, in terms of crafting, like all the other planks (create sticks, crafting tables, chests, etc...) and so after researching for a while and looking at the forge documentation I tried to register the planks on the Ore Dictionary, on my BlockInit class after registering all the blocks, like so: OreDictionary.registerOre("plankWood", new ItemStack(ModBlocks.MODPLANKS.getDefaultState().withProperty(BlockPlankBase.VARIANT, BlockPlankBase.EnumType.SPRING).getBlock())); OreDictionary.registerOre("plankWood", new ItemStack(ModBlocks.MODPLANKS.getDefaultState().withProperty(BlockPlankBase.VARIANT, BlockPlankBase.EnumType.AUTUMN).getBlock())); OreDictionary.registerOre("plankWood", new ItemStack(ModBlocks.MODPLANKS.getDefaultState().withProperty(BlockPlankBase.VARIANT, BlockPlankBase.EnumType.SUMMER).getBlock())); OreDictionary.registerOre("plankWood", new ItemStack(ModBlocks.MODPLANKS.getDefaultState().withProperty(BlockPlankBase.VARIANT, BlockPlankBase.EnumType.WINTER).getBlock())); also tried to instead of creating a new ItemStack just use the block but it also failed. The problem is (I think) that I'm using variants to create the different types of planks. Inside the Planks class I have the following to make this possible: public static enum EnumType implements IStringSerializable { AUTUMN(0, "autumn"), SPRING(1, "spring"), WINTER(2, "winter"), SUMMER(3, "summer"); private static final BlockPlankBase.EnumType[] META_LOOKUP = new BlockPlankBase.EnumType[values().length]; private final int meta; private final String name, unlocalizedName; private EnumType(int meta, String name) { this(meta, name, name); } private EnumType(int meta, String name, String unlocalizedName) { this.name = name; this.meta = meta; this.unlocalizedName = unlocalizedName; } @Override public String getName() { return this.name; } public int getMeta() { return this.meta; } public String unlocalizedName() { return this.unlocalizedName; } @Override public String toString() { return this.name; } public static BlockPlankBase.EnumType byMetadata(int meta) { return META_LOOKUP[meta]; } static { for (BlockPlankBase.EnumType blockplankbase$enumtype : values()) { META_LOOKUP[blockplankbase$enumtype.getMeta()] = blockplankbase$enumtype; } } } So as you can see it is heavily inspired on the vanilla code (BlockPlanks). Coming back to the problem, when I try to register the blocks on the Ore Dictionary it only works for the autumn planks, because it is the first one declared on the EnumType in the BlockCustomPlanks class that I made. I've tried to change the declarations inside the EnumType and put, for exempla, Winter first instead of Autumn and it then only works for the Winter planks. I'm guessing that it only works for the objects of this class with data = 0. I've been around this problem for a couple of days and I can't resolve the issue. I would appreciate if anyone could shine a light on this problem! Thank you! Edited September 1, 20196 yr by DiogoRod
August 31, 20196 yr Have called hasSubtypes(true) in your item class constructor? 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.
August 31, 20196 yr Author 27 minutes ago, Draco18s said: Have called hasSubtypes(true) in your item class constructor? Nop, I've tried to do that after your suggestion but it just tells me that there is no function with that name and asks me if I want to create it... should I? Cause I have no clue how... I'm a bit confused ahah Maybe it will be easier to understand the problem if I show the class itself: public class BlockPlankBase extends Block{ public static final PropertyEnum<BlockPlankBase.EnumType> VARIANT = PropertyEnum.<BlockPlankBase.EnumType>create( "variant", BlockPlankBase.EnumType.class); public BlockPlankBase(String name) { super(Material.WOOD); this.setUnlocalizedName(name); this.setRegistryName(name); this.setSoundType(SoundType.WOOD); this.setHardness(1.8F); this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlankBase.EnumType.AUTUMN)); } @Override public int damageDropped(IBlockState state) { return ((BlockPlankBase.EnumType) state.getValue(VARIANT)).getMeta(); } @Override public void getSubBlocks(CreativeTabs intemIn, NonNullList<ItemStack> items) { for (BlockPlankBase.EnumType blockplankbase$enumtype : BlockPlankBase.EnumType.values()) { items.add(new ItemStack(this, 1, blockplankbase$enumtype.getMeta())); } } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(VARIANT, BlockPlankBase.EnumType.byMetadata(meta)); } @Override public int getMetaFromState(IBlockState state) { return state.getValue(VARIANT).getMeta(); } @Override public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos))); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { VARIANT }); } public static enum EnumType implements IStringSerializable { AUTUMN(0, "autumn"), SPRING(1, "spring"), WINTER(2, "winter"), SUMMER(3, "summer"); private static final BlockPlankBase.EnumType[] META_LOOKUP = new BlockPlankBase.EnumType[values().length]; private final int meta; private final String name, unlocalizedName; private EnumType(int meta, String name) { this(meta, name, name); } private EnumType(int meta, String name, String unlocalizedName) { this.name = name; this.meta = meta; this.unlocalizedName = unlocalizedName; } @Override public String getName() { return this.name; } public int getMeta() { return this.meta; } public String unlocalizedName() { return this.unlocalizedName; } @Override public String toString() { return this.name; } public static BlockPlankBase.EnumType byMetadata(int meta) { return META_LOOKUP[meta]; } static { for (BlockPlankBase.EnumType blockplankbase$enumtype : values()) { META_LOOKUP[blockplankbase$enumtype.getMeta()] = blockplankbase$enumtype; } } } } Thanks for the attention btw. Edited August 31, 20196 yr by DiogoRod
August 31, 20196 yr 1 hour ago, Draco18s said: your item class 1 hour ago, DiogoRod said: extends Block That's a block. You need an Item to call that method. https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/item/ItemOreBlock.java#L12 Edited August 31, 20196 yr by Draco18s 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.
August 31, 20196 yr Author 18 minutes ago, Draco18s said: That's a block. You need an Item to call that method. Ahhhh yeah, on the Item it is indeed on the constructor. Sorry, got confused for a second. public class ItemTreeVariants extends ItemBlock{ public ItemTreeVariants(Block block) { super(block); setHasSubtypes(true); setMaxDamage(0); } @Override public String getUnlocalizedName(ItemStack stack) { return super.getUnlocalizedName() + "_" + ((IMetaName) this.block).getSpecialName(stack); } @Override public int getMetadata(int damage) { return damage; } } At the time when I created the BlockPlankBase that I showed before I also created this class that on the BlockInit class is called in order to register the item block that corresponds to the BlockPlank itself, like so: // Tree public static final Block MODPLANKS = new BlockPlankBase("mod_planks"); public static void register() { registerBlockVariants(MODPLANKS, new ItemTreeVariants(MODPLANKS)); regPlanks(); } public static void registerBlockVariants(Block block, ItemBlock itemblock) { ForgeRegistries.BLOCKS.register(block); block.setCreativeTab(Reference.MODTAB); itemblock.setRegistryName(block.getRegistryName()); ForgeRegistries.ITEMS.register(itemblock); } public static void regPlanks() { OreDictionary.registerOre("plankWood", new ItemStack(ModBlocks.MODPLANKS.getDefaultState() .withProperty(BlockPlankBase.VARIANT, BlockPlankBase.EnumType.SPRING).getBlock())); OreDictionary.registerOre("plankWood", new ItemStack(ModBlocks.MODPLANKS.getDefaultState() .withProperty(BlockPlankBase.VARIANT, BlockPlankBase.EnumType.AUTUMN).getBlock())); OreDictionary.registerOre("plankWood", new ItemStack(ModBlocks.MODPLANKS.getDefaultState() .withProperty(BlockPlankBase.VARIANT, BlockPlankBase.EnumType.SUMMER).getBlock())); OreDictionary.registerOre("plankWood", new ItemStack(ModBlocks.MODPLANKS.getDefaultState() .withProperty(BlockPlankBase.VARIANT, BlockPlankBase.EnumType.WINTER).getBlock())); } I hope I'm not posting to much code, but sometimes I feel like it's easier to explain by posting the code and English is not my first language so I do apologize if say anything that sounds a bit confusing from time to time. Either way, thanks for now!
August 31, 20196 yr 31 minutes ago, DiogoRod said: sometimes I feel like it's easier to explain by posting the code and English is not my first language so I do apologize if say anything that sounds a bit confusing from time to time. No worries, you're doing pretty good so far. 31 minutes ago, DiogoRod said: Either way, thanks for now! Got it working? 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.
August 31, 20196 yr Author Quote Got it working? Nop, it still is doing the same thing, only one of the planks is being registered (the one with data=0), I'm back to the same initial problem. I was thinking that maybe I could use the ItemBlock class as so: OreDictionary.registerOre("plankWood", new ItemTreeVariants(MODPLANKS.getDefaultState().withProperty(BlockPlankBase.VARIANT, BlockPlankBase.EnumType.SPRING).getBlock())); also tried OreDictionary.registerOre("plankWood", new ItemTreeVariants(MODPLANKS)); But it also doesn't work so I'm out of ideas. Any suggestions are appreciated, thank you! Edited August 31, 20196 yr by DiogoRod
August 31, 20196 yr 1 hour ago, DiogoRod said: ForgeRegistries.BLOCKS.register(block); block.setCreativeTab(Reference.MODTAB); itemblock.setRegistryName(block.getRegistryName()); ForgeRegistries.ITEMS.register(itemblock); You should be using the Registry events to register your blocks and items, not this. @SubscribeEvent public void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll( //items here ); } 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.
August 31, 20196 yr Author 2 hours ago, Draco18s said: You should be using the Registry events to register your blocks and items, not this. @SubscribeEvent public void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll( //items here ); } Ok, so... I've made some progress and I am now using the registry events for everything else except the plank blocks which are the one with the variants because everytime I try it just... doesn't work. @SubscribeEvent public static void onItemRegister(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0])); } @SubscribeEvent public static void onBlockRegister(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0])); } @SubscribeEvent @SideOnly(Side.CLIENT) public static void onModelRegister(ModelRegistryEvent event) { for(Item item : ModItems.ITEMS) { if(item instanceof IHasModel) { ((IHasModel)item).registerModels(); } } for(Block block : ModBlocks.BLOCKS) { if(block instanceof IHasModel) { ((IHasModel)block).registerModels(); } } } I know why it does not work, it's because I'm not adding the planks to the Arrays BLOCKS and ITEMS but I can't seem to be able to add the planks... how can I explain this... Everytime I try to add them to the Arrays, both in the constructor in the BlockPlanksBase class or in BlockInit I can only add one instead of 4, meaning that I can't add the 4 different planks only the block "mod_planks" instead of "mod_planks_autumn", "mod_planks_spring", etc... and so later it asks for the model and textures for "mod_planks" instead of the others. Thank you for the attention! Edited August 31, 20196 yr by DiogoRod
August 31, 20196 yr 2 minutes ago, DiogoRod said: ModBlocks.BLOCKS What type is this? 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.
August 31, 20196 yr Author 3 minutes ago, Animefan8888 said: What type is this? Blocks. It's an ArrayList of Blocks public static final List<Block> BLOCKS = new ArrayList<Block>();
August 31, 20196 yr 2 minutes ago, DiogoRod said: Blocks. It's an ArrayList of Blocks Show how you're adding them to the list. 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.
August 31, 20196 yr Author 12 minutes ago, Animefan8888 said: Show how you're adding them to the list. I'm doing it like this on the constructor of the BlockPlankBase class: public BlockPlankBase(String name) { super(Material.WOOD); this.setUnlocalizedName(name); this.setRegistryName(name); this.setSoundType(SoundType.WOOD); this.setHardness(1.8F); ModBlocks.BLOCKS.add(this); ModItems.ITEMS.add(new ItemTreeVariants(this).setRegistryName(this.getRegistryName())); this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlankBase.EnumType.AUTUMN)); }
August 31, 20196 yr 28 minutes ago, DiogoRod said: meaning that I can't add the 4 different planks Have you overriden Item#getSubItems? 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.
August 31, 20196 yr Author 5 minutes ago, Animefan8888 said: Have you overriden Item#getSubItems? yes, I did it like so: @Override public void getSubBlocks(CreativeTabs intemIn, NonNullList<ItemStack> items) { for (BlockPlankBase.EnumType blockplankbase$enumtype : BlockPlankBase.EnumType.values()) { items.add(new ItemStack(this, 1, blockplankbase$enumtype.getMeta())); } } the whole class is up on my second post in this thread
August 31, 20196 yr 44 minutes ago, DiogoRod said: if(block instanceof IHasModel) { Don't use IHasModel. This is your problem. For one your planks block doesn't use it. So no models are applied. Second all Items have a model. So you can just do something like for (Item item : ITEMS) { ModelLoader.setCustomModelLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory")); } And in your case since you have meta items don't add them to the list and instead do them directly like. for (Enum enum : EnumType.values()) { ModelLoader.setCustomModelLocation(Item.getItemFromBlock(ModBlocks.SOME_PLANK), enum.getMeta(), new ModelResourceLocation(ModBlocks.SOME_PLANK.getRegistryName().toString() + "_" + enum.getName(), "inventory")); Something like that. 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.
September 1, 20196 yr Author I found the problem and it is now working properly! Apparently I was not calling the function OreDictionary.registerOre with the proper arguments. It seems that when you have variants you need to use the constant WILDCARD_VALUE. All is good now. Thank you so much to everyone who tried to help me!
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.