Jump to content

Recommended Posts

Posted

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 :D)?

Posted

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?

 

 

Posted

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.

Posted

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;
        }
    }
}

Posted

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!!!

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.

Announcements



×
×
  • Create New...

Important Information

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