Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello, 

 

I have a problem and I can't find the source.
I would like to create a block with a model but in game, I don't have a texture on the block but I have the texture on the item in the inventory and thrown it on the floor. As in the picture
 

Spoiler

eUdrJ09.png

 

My code

Spoiler

blockstates.json

Spoiler


{
  "forge_marker": 1,
  "defaults": {
    "model": "goblin:mine_lvl_0"
  },
  "variants": {
    "normal": [{}],
    "inventory": [{"transform": "forge:default-block"}]
  }
}

 

models.json

Spoiler


{
    "forge_marker": 1,
    "textures": {
        "all": "goblin:blocks/mine_lvl_0",
        "particle": "goblin:blocks/mine_lvl_0"
    },
    "elements": [
        {
            "from": [2,1,2],
            "to": [14,2,14],
            "faces": {
                "up": {
                    "uv": [0,0,16,16],
                    "texture": "#all"
                },
                "down": {
                    "uv": [0,0,16,16],
                    "texture": "#all"
                },
                "west": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [3,2,3],
            "to": [13,3,12],
            "faces": {
                "up": {
                    "uv": [0,0,14,14],
                    "texture": "#all"
                },
                "west": {
                    "uv": [2,11,16,16],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [4,3,4],
            "to": [11,4,11],
            "faces": {
                "up": {
                    "uv": [0,0,14,13],
                    "texture": "#all"
                },
                "west": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [5,11,16,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [5,4,5],
            "to": [10,5,10],
            "faces": {
                "up": {
                    "uv": [0,0,16,12],
                    "texture": "#all"
                },
                "west": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [5,11,16,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [8,5,7],
            "to": [10,6,9],
            "faces": {
                "up": {
                    "uv": [0,0,11,12],
                    "texture": "#all"
                },
                "west": {
                    "uv": [10,11,16,16],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [5,11,16,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [6,5,6],
            "to": [7,6,9],
            "faces": {
                "up": {
                    "uv": [0,3,16,16],
                    "texture": "#all"
                },
                "west": {
                    "uv": [4,10,16,16],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [12,11,16,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [11,11,16,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [8,6,7],
            "to": [9,7,8],
            "faces": {
                "up": {
                    "uv": [0,0,16,16],
                    "texture": "#all"
                },
                "west": {
                    "uv": [0,0,16,16],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,0,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [0,0,16,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [0,0,16,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [5,2,12],
            "to": [12,3,13],
            "faces": {
                "up": {
                    "uv": [0,12,16,16],
                    "texture": "#all"
                },
                "west": {
                    "uv": [11,11,16,16],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [11,3,8],
            "to": [12,4,10],
            "faces": {
                "up": {
                    "uv": [0,0,14,14],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [0,10,11,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [0,13,12,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [11,3,4],
            "to": [12,4,7],
            "faces": {
                "up": {
                    "uv": [0,0,13,14],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [0,11,2,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [0,8,13,16],
                    "texture": "#all"
                }
            }
        },
        {
            "from": [1,0,1],
            "to": [15,1,15],
            "faces": {
                "up": {
                    "uv": [0,0,16,16],
                    "texture": "#all"
                },
                "down": {
                    "uv": [0,0,16,16],
                    "texture": "#all"
                },
                "west": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "east": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "north": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                },
                "south": {
                    "uv": [0,11,16,16],
                    "texture": "#all"
                }
            }
        }
    ]
}

 

 

mine_lvl_0.java

Spoiler


public class mine_lvl_0 extends BlockBase{

	public mine_lvl_0() {
		super(Material.ROCK, "mine_lvl_0");
	}

	@Override
	public boolean isOpaqueCube(IBlockState state) {
		return false;
	}
	
	@Override
	public boolean isFullCube(IBlockState state) {
		return false;
	}

}

 

 

ModBlack.java

Spoiler


public class ModBlock {

	public static mine_lvl_0 mine0 = new mine_lvl_0();

	// RegistryEvent.Register<Block>
	public static void register(IForgeRegistry<Block> registry) {
		registry.registerAll(mine0);
	}

	// RegistryEvent.Register<Item>
	public static void registerItemBlocks(IForgeRegistry<Item> registry) {
		registry.registerAll(mine0.createItemBlock());
	}

	// ModelRegistryEvent
	public static void registerModel() {
		ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(mine0), 0,
				new ModelResourceLocation(mine0.getRegistryName(), "inventory"));
	}

}

 

BlockBase.java

Spoiler


public class BlockBase extends Block{

	protected String name;
	
	public BlockBase(Material material, String name) {
		super(material);
		
		this.name = name;
		
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.creativeTab);
	}
	
	public void registerItemModel(Item itemBlock){
		Main.proxy.registerItemRenderer(itemBlock, 0, name);
	}
	
	public Item createItemBlock(){
		return new ItemBlock(this).setRegistryName(getRegistryName());
	}
	
	@Override
	public BlockBase setCreativeTab(CreativeTabs tab){
		super.setCreativeTab(tab);
		return this;
	}

}

 

Thank you very much 

 

Edited by THEJean_Kevin
Solved

  • Author

I don't have any errors in the console, but I think I made a mistake when I register the block but where?

 

The full code : https://github.com/THEJean-Kevin/goblin

This is very confusing:

https://github.com/THEJean-Kevin/goblin/blob/master/src/main/java/com/mineaurion/tjk/goblin/block/ModBlock.java#L17

1) Class names should start with an upper case letter

2) You really should use the most general-case Type possible (e.g. Block mine0 = new Mine_Lv_0();) so that people reading your code can understand it better.

3) Then if you need to, you can cast (I don't like seeing createItemBlock() in a base block class that all your blocks extend, but it's not that terrible).

4) Even better, make your class names include the base class, e.g. BlockMine_Lv_0

 

Oh god this is disgusting:

https://github.com/THEJean-Kevin/goblin/blob/master/src/main/java/com/mineaurion/tjk/goblin/block/ModBlock.java#L31

You take a client-side-only event, call a piece of code that is not marked Side Only, then just forward the method call to your Proxy.

Just do Main.proxy.registerItemRenderer(Item.getItemFromBlock(mine0), 0, name);

 

https://github.com/THEJean-Kevin/goblin/blob/master/src/main/java/com/mineaurion/tjk/goblin/proxy/clientProxy.java#L23

Use item.getRegistryName() instead of References.modid+":"+name

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.

  • Author

I'm sry for the basic mistakes like name class. 

 

It's my first mod and I try to understand how it work. I just follow some tutorials but I don't understand why it don't work for me?

 

I will change what do you sayed draco18s and I come back here if I have always this problem.

 

Thank you for taking the time for me

 
3 minutes ago, THEJean_Kevin said:

I'm sry for the basic mistakes like name class.

It's a Java convention thing, that. Static values are in all upper case, class names are UpperCamelCast, variables and function names are lowerCamelCase.

The BlockFoo and BlockBar and ItemBaz are an MCP naming convention, but one that I happen to like.

 

After that, making method calls that invoke more method calls is just ridiculous. The only reason to do that is if the method actually adds something from its scope context (that isn't accessible outside it).  For example, if I want to have items that define their model via NBT data I still want to register it as normal, but I need additional information from the class / class instance, so I have this method:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/industry/item/ItemCastingMold.java#L89

Or this method, for custom IStateMapper implementations:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/flowers/block/BlockOreFlower1.java#L160

And when I need those functions I can just cast to the interface. Or use generic covariance magic:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L75

The cast here is actually unnecessary due to said magic (block is of Type T which is defined as block a Block and an IBlockWithMapper):

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L79

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.

  • Author

Thx you draco18s.

 

I found the problem. I just forgot tout put @SubscribeEvent on registerBlock function in the main class.

 

Thank you for your advice and for explaining some things to me

 

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.