-
[1.12.2] [SOLVED] Add Custom Woods made with Variants to Ore Dictionary
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!
-
[1.12.2] [SOLVED] Add Custom Woods made with Variants to Ore Dictionary
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
-
[1.12.2] [SOLVED] Add Custom Woods made with Variants to Ore Dictionary
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)); }
-
[1.12.2] [SOLVED] Add Custom Woods made with Variants to Ore Dictionary
Blocks. It's an ArrayList of Blocks public static final List<Block> BLOCKS = new ArrayList<Block>();
-
[1.12.2] [SOLVED] Add Custom Woods made with Variants to Ore Dictionary
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!
-
[1.12.2] [SOLVED] Add Custom Woods made with Variants to Ore Dictionary
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!
-
[1.12.2] [SOLVED] Add Custom Woods made with Variants to Ore Dictionary
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!
-
[1.12.2] [SOLVED] Add Custom Woods made with Variants to Ore Dictionary
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.
-
[1.12.2] [SOLVED] Add Custom Woods made with Variants to Ore Dictionary
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!
IPS spam blocked by CleanTalk.