Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.11.2] Registering blocks


Recommended Posts

Hey everyone,

 

I am having problems with the new way of registering blocks.

I can register items just fine, but blocks seem to fail (I get no console error, but my blocks are not appearing in my creative tab, nor can I give them to player via eventhandler)

 

Registering the blocks (the events  are getting called, I double checked that)

@SubscribeEvent
public void registerBlocks(RegistryEvent.Register<Block> event) {
	event.getRegistry().registerAll(blockkitchen);
}
  
@SubscribeEvent
public void registerModels(ModelRegistryEvent event) {
	registerBlock(blockkitchen);
}
  
private void registerBlock(Block block) {
	ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(),"inventory"));
}
  

Important parts of the block class

public class BlockKitchen extends ProgressingBlock{
	public BlockKitchen() {
		super(Material.PISTON, "blockkitchen");
	}
}

public class ProgressingBlock extends Block {

	public ProgressingBlock(Material materialIn, String name) {
		super(materialIn);
		setRegistryName(name);
		setUnlocalizedName(name);
		setCreativeTab(ProgressingPlayer.CREATIVE_TAB);

	}
}

 

assets/progressingplayer/blockstates/blockkitchen.json

{
    "variants": {
        "normal": { "model": "progressingplayer:blockkitchen" }
    }
}

assets/progressingplayer/models/block/blockkitchen.json

{
    "parent": "block/cube_all",
    "textures": {
        "all": "progressingplayer:blocks/blockkitchen"
    }
}

 

assets/progressingplayer/models/item/blockkitchen.json

{
    "parent":"progressingplayer:block/blockkitchen",
    "display": {
        "thirdperson": {
            "rotation": [ 10, -45, 170 ],
            "translation": [ 0, 1.5, -2.75 ],
            "scale": [ 0.375, 0.375, 0.375 ]
        }
    }
}

 

texture is under

assets/progressingplayer/textures/blocks/blockkitchen.json

 

Any help is appreciated!

 

Greetz,

failender

 

Edited by Failender
fixed title
Link to post
Share on other sites

You never create (and register) an item version of your block.

Edited 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.

Link to post
Share on other sites

RegistryEvent.Register and ModelRegistryEvent are both fired before preInit, so they need to be handled by static @SubscribeEvent methods in a class annotated with @Mod.EventBusSubscriber.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to post
Share on other sites

not exactly true @Choonster. You can just register the event handler in the constructor of your main class!

public ProgressingPlayer() {
	MinecraftForge.EVENT_BUS.register(new RegisterEventHandler());
}

I guess thats true Draco! Item.getItemFromBlock returns the block for air..

 I fixxed it using this way, I am not sure if there is any better feel free to correct me

 

@SubscribeEvent
public void registerModels(ModelRegistryEvent event) {

	registerItem(learnscroll);
	registerBlock(blockkitchen);
	registerBlock(blockforge);
}
@SubscribeEvent
public void registerItems(RegistryEvent.Register<Item> event) {
	event.getRegistry().registerAll(learnscroll);
	event.getRegistry().registerAll(blockItems);
		
	blockItems = null;
		
}

@SubscribeEvent
public void registerBlocks(RegistryEvent.Register<Block> event) {
	registerAll(event, blockkitchen, blockforge);
}
	
private ItemBlock[] blockItems;
	
private void registerAll(RegistryEvent.Register<Block> event,Block... blocks ) {
	blockItems = new ItemBlock[blocks.length];
	event.getRegistry().registerAll(blocks);
	for (int i = 0; i < blocks.length; i++) {
		blockItems[i] = new ItemBlock(blocks[i]);
		blockItems[i].setRegistryName(blocks[i].getRegistryName());
	}
}

private void registerItem(Item item) {
	ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

private void registerBlock(Block block) {
	ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(),"inventory"));
}

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.