Posted May 20, 201510 yr I'm making a mod including some custom blocks. Now I need to make them clickable(like chests or workbenches). This is an example of the code of my custom block: public class LobbyBlock extends Block{ public LobbyBlock(Material rock) { super(rock); this.setBlockName("LobbyBlock"); this.setBlockTextureName(Main.MODID + ":" + "0"); this.setCreativeTab(Main.PAYDAY2Tab); this.setLightLevel(1F); this.setLightOpacity(2555); } } And this is the code I currently have in the main class: @Mod(modid = Main.MODID, version = Main.VERSION) public class Main { public static final String MODID = "PAYDAY2"; public static final String NAME = "PAYDAY 2 RELOADED"; public static final String VERSION = "0.01"; public static Block LobbyBlock = new LobbyBlock(Material.rock); @EventHandler public void preInit(FMLPreInitializationEvent event) { GameRegistry.registerBlock(LobbyBlock, "LobbyBlock"); } @EventHandler public void Init(FMLInitializationEvent event) { } @EventHandler public void postInit(FMLPostInitializationEvent event) { } } What should I add to make it do what I want(the clickableness )?
May 21, 201510 yr Author so I add: ..... this.onBlockActivated(); } @Override public void onBlockActivated(){ [action] } to the block's class right? And another question... does it matter if I don't put the "@Override" there?
May 21, 201510 yr And another question... does it matter if I don't put the "@Override" there? Yes, because you're doing it wrong. Eclipse will tell you "hey, that function isn't overriding anything." Which should prompt you go to find the method you're trying to override and make sure you have correctly copied the method signature. Also, you don't call the function yourself. 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.
May 21, 201510 yr Author Ok, I've figured it out this way: public class LobbyBlock extends Block{ public float eyeHeight; public LobbyBlock(Material rock) { super(rock); this.setBlockName("LobbyBlock"); this.setBlockTextureName(Main.MODID + ":" + "0"); this.setCreativeTab(Main.PAYDAY2Tab); this.setLightLevel(1F); this.setLightOpacity(2555); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { if (world.isRemote) { return true; } else { System.out.println("test"); return true; } } }
May 21, 201510 yr Ok, I've figured it out this way: public class LobbyBlock extends Block{ public float eyeHeight; public LobbyBlock(Material rock) { super(rock); this.setBlockName("LobbyBlock"); this.setBlockTextureName(Main.MODID + ":" + "0"); this.setCreativeTab(Main.PAYDAY2Tab); this.setLightLevel(1F); this.setLightOpacity(2555); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { if (world.isRemote) { return true; } else { System.out.println("test"); return true; } } } You must return false onClient... YOU MUST!!! Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
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.