heyitsmenobodyy Posted February 18, 2019 Share Posted February 18, 2019 I'm trying to get into minecraft modding.. But onBlockActivated just will not do anything. public class BlockBase extends Block implements IHasModel { public BlockBase(String name, Material material) { super(material); setUnlocalizedName(name); setRegistryName(name); setCreativeTab(Main.firsttab); ModBlocks.BLOCKS.add(this); ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName())); } @Override public void registerModels() { Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory"); } public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { return false; } playerIn.sendMessage(new TextComponentString("test: " + playerIn.getDisplayNameString())); Main.logger.warn("Right click"); return true; } } Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted February 18, 2019 Share Posted February 18, 2019 I am not sure this is the method's signature and you don't have an override annotation over it. Place that annotation and make sure the signature is correct. Also don't manually override methods, use your IDE. As for other issues: 25 minutes ago, heyitsmenobodyy said: BlockBase Don't use BlockBase, there is already a BlockBase, it's called Block. 25 minutes ago, heyitsmenobodyy said: ModBlocks.BLOCKS.add(this); ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName())); Don't ever use static initializers. Instantinate your stuff directly in the appropriate registry event. 25 minutes ago, heyitsmenobodyy said: IHasModel IHasModel is stupid. All items need models and nothing about model registration requires access to private/protected data. Register your models directly in the ModelRegistryEvent. You can even do it with a loop and write a metric ton less code. And even if you don't use a loop you still write 1/3 of the code you would with IHasModel. 1 Quote Link to comment Share on other sites More sharing options...
DavidM Posted February 19, 2019 Share Posted February 19, 2019 (edited) public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) This is how Block#onBlockActivated is defined. You are not overriding it as your parameters are wrong. Edited February 19, 2019 by DavidM 1 Quote Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support. Link to comment Share on other sites More sharing options...
Cadiboo Posted February 19, 2019 Share Posted February 19, 2019 (edited) 14 hours ago, V0idWa1k3r said: Don't use BlockBase, there is already a BlockBase, it's called Block What: Not using an object base class.Why: Using an object base class (commonly called BlockBase or ItemBase) is unnecessary and is an anti-pattern. There is already a BlockBase class, it’s the minecraft Block class. Making a class just to have its children inherit default implementations of methods goes against the OOP principle of Composition over Inheritance.Consequences: Using a class like this stops you from extending other classes and because lots of minecraft code uses instanceof checks to specially handle logic, you are likely to encounter weird and hard-to-fix bugs.How: Instead of putting all your common logic in one class and extending it, extract the logic to utility methods. For example: Instead of calling setRegistryName, setTranslationKey, etc. inside your object base’s constructor, extract it to a helper method and call it on every object when you create it. In this example setup calls the above methods. registry.register(setup(new CustomItem(), "custom_item")); 14 hours ago, V0idWa1k3r said: Don't ever use static initializers. Instantinate your stuff directly in the appropriate registry event What: Not using static initialisers.Why: Using static initialisers does not allow you to control when your objects are created or the order in which your objects are created.Consequences: Using static initialisers prevents other mods from overriding your objects, prevents forge from being able to dynamically load/unload mods and can cause weird, unreproducible crashes.How: Use the @ObjectHolder annotation if you need static references to your objects and create & register your objects in the appropriate registry event. (Note: before registry events Modders created and registered their items in preInit. This practice became out of date in 1.7 with the introduction of registry events, and is no longer possible in 1.13). 14 hours ago, V0idWa1k3r said: IHasModel What: Not using an interface to register models.Why: This interface (commonly called IHasModel) is unnecessary. All items need models and nothing about model registration requires private or protected data.Consequences: This interface makes you write 4 lines of code in each class and 2+ lines of code in your registry event, when 1 or 2 lines of code could accomplish the exact same thing. It also leads to weird bugs when you forget to make your object implement the interface.How: Simply register each model in the registry event (1 line of code for each model) or write a loop that does it for you (1 or 2 lines depending on the implementation). For example: Write out registerModel(item, meta, variant) for each item and variant or write a loop like this for (Item item : allModItemsAndItemBlocks) registerModel(item, meta, variant); A list of all your items can be acquired in many ways, such as looping over registries and checking domain, keeping your own list, looping over registries and using an instanceof check etc. Read more code common issues & solutions at https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93 Edited February 19, 2019 by Cadiboo 3 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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 More sharing options...
heyitsmenobodyy Posted February 19, 2019 Author Share Posted February 19, 2019 Thanks all of you for the help, I got it working now. package com.shoshonerp.shoshonerp.blocks; import com.shoshonerp.shoshonerp.Main; import com.shoshonerp.shoshonerp.init.ModBlocks; import com.shoshonerp.shoshonerp.init.ModItems; import com.shoshonerp.shoshonerp.util.Reference; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; public class BlockBase extends Block { public BlockBase(String name, Material material) { super(material); this.setCreativeTab(Main.firsttab); this.setRegistryName(Reference.MOD_ID, name); this.setUnlocalizedName(this.getRegistryName().toString()); ModBlocks.BLOCKS.add(this); ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName())); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { Main.logger.info("onBlockActivated called"); return true; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.