Jump to content

Muliple blocks using the same blockstate ?


Franckyi

Recommended Posts

Hi

 

I'm developing a mod that will contain a lot of texture variations of the same block.

The way I'm doing this isn't good, I mean it's VERY long to copy, paste and rename the .json blockstate files for each block variation. So, I know it's possible to have multiple blocks using the same blockstate JSON file, but I don't know how to do this. I'm a beginner at modding (I'm OK with Java).

All my files can be found here : https://github.com/Franckyi/Roads

 

Can someone help me ?

 

[EDIT] I'm using 1.10.2 version of Minecraft and 2099 version of Forge.

[EDIT2] In the Github repository, I haven't done all the .json files for the "LineSolid" variations of the blocks.

Link to comment
Share on other sites

Ok, but then :

I have to register my Block (and my ItemBlock) only one time for all variants ?

If true, I don't know how to set up the constructor of my Block.

I explain :

The Block that I create has 3 properties : the Color, the State and the Extra. All those properties are in basic enums.

This is how I was creating all my blocks before :

package com.franckyi.roads.blocks;

import java.util.ArrayList;
import java.util.List;

import com.franckyi.roads.Reference;
import com.franckyi.roads.RoadsMod;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;

public class BlockAsphalt extends Block {

public BlockAsphalt(AsphaltBlockColor color, AsphaltBlockState state, AsphaltBlockExtra extra) {
	super(Material.ROCK);
	setUnlocalizedName(
			Reference.RoadsBlocks.ASPHALT.getUnlocalizedName() + color.color + state.state + extra.extra);
	setRegistryName(Reference.RoadsBlocks.ASPHALT.getRegistryName() + color.color + state.state + extra.extra);
	setCreativeTab(RoadsMod.tab);
}

public static List<Block> getAllBlocks() {
	List<Block> list = new ArrayList<Block>();
	for (AsphaltBlockColor color : AsphaltBlockColor.values()) {
		for (AsphaltBlockState state : AsphaltBlockState.values()) {
			for (AsphaltBlockExtra extra : AsphaltBlockExtra.values()) {
				list.add(new BlockAsphalt(color, state, extra));
			}
		}
	}
	return list;
}

private enum AsphaltBlockColor {

	LIGHT("Light"), MEDIUM("Medium"), DARK("Dark");

	private String color;

	AsphaltBlockColor(String color) {
		this.color = color;
	}

}

private enum AsphaltBlockState {

	NORMAL("Normal"), DAMAGED("Damaged"), BROKEN("Broken");

	private String state;

	AsphaltBlockState(String state) {
		this.state = state;
	}

}

private enum AsphaltBlockExtra {

	NONE(""), LINESOLID("LineSolid");

	private String extra;

	AsphaltBlockExtra(String extra) {
		this.extra = extra;
	}

}

}

 

This is how I was registering Blocks :

package com.franckyi.roads.blocks;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class RoadsBlocks {

public static List<Block> asphalts;

public static void init() {
	asphalts = BlockAsphalt.getAllBlocks();
}

public static void register() {
	for (Block asphalt : asphalts) {
		registerBlock(asphalt);
	}
}

private static void registerBlock(Block block) {
	GameRegistry.register(block);
	ItemBlock item = new ItemBlock(block);
	item.setRegistryName(block.getRegistryName());
	GameRegistry.register(item);
}

public static void registerRenders() {
	for (Block asphalt : asphalts) {
		registerRender(asphalt);
	}
}

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

}

So now, I know I'll not register the renders like this, but using the ModelLoader.setCustomStateMapper() method.

I have to create a new StateMapperBase for this method :

package com.franckyi.roads.blocks;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;

public class AsphaltStateMapper extends StateMapperBase {

@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
	return new ModelResourceLocation("BlockAsphalt" + state.getProperties().get("COLOR") + state.getProperties().get("STATE") + state.getProperties().get("EXTRA"), "inventory");
}

}

 

That means that in my Block constructor, I must add the properties to the BlockState, but that means that I have to create a new Block for every properties combination possible, no ?

 

PS : all the sources are in the first post, if you need.

Link to comment
Share on other sites

Warning: StateMapperBase is marked @SideOnly(Client).

You cannot operate with it in common code.

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 comment
Share on other sites

I'm already using a proxy, but thanks for reminding me :)

 

It's one of those things I bumped into without realizing it and had to do some refactoring.

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 comment
Share on other sites

Hey, it's me again. I had trouble with the StateMapperBase class and I saw this tutorial : http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/blockstates-and-metadata/

And it works well, I just had to create the 9 different blocks with 3 "colors" and 3 "states", then to add the "extra" property to all these blocks (because as I saw, there can be only 16 different variations of a block, and 3 colors * 3 states * 2 extras = 18 blocks (and there will be more than 2 extras in the future)).

I updated my github repository : https://github.com/Franckyi/Roads

All blocks variants are registered in the game and in my custom creative tab. I still have a small problem :

60baedabc4.jpg

As you can see, everything goes well for the "extra=none" variant. But textures in inventory for "extra=linesolid" variants are missing whereas they aren't for the world block, and I don't have any errors in the console. Can someone help me ? (you can look at the source to check file names and content).

 

[EDIT] : I saw that my blockstate files name had uppercase letter (and I only used lowercase letters in my registry/unlocalized names so I'll don't have to change everything if I update my mod to 1.11). But it didn't solve the problem. (I still don't know why I didn't have errors before I changed that, it ignores blockstates files name's case ?)

Link to comment
Share on other sites

You need to supply an item model.

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 comment
Share on other sites

[me=Draco18s]looks at your Git repo[/me]

 

	private static void registerRender(Block block, int meta, String file) {
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
    .register(Item.getItemFromBlock(block), meta, new ModelResourceLocation(Reference.MODID + ":" + file, "inventory"));
}

 

Why are you still using the ModelMesher?  You should be using ModelLoader.setCustomModelResourceLocation(...)

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 comment
Share on other sites

Yeah, I know there is a better way to do that. In the tutorial (outdated at this point) it registers like tkat. I change it now ;)

But the bug is still here...and it does that with all custom blocks now (I updated my repository).

 

[EDIT] Alright, I think I know where I'm wrong. I forgot a bracket in ItemBlock models.

Link to comment
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.
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Dalam dunia perjudian online yang berkembang pesat, mencari platform yang dapat memberikan kemenangan maksimal dan hasil terbaik adalah impian setiap penjudi. OLXTOTO, dengan bangga, mempersembahkan dirinya sebagai jawaban atas pencarian itu. Sebagai platform terbesar untuk kemenangan maksimal dan hasil optimal, OLXTOTO telah menciptakan gelombang besar di komunitas perjudian online. Satu dari banyak keunggulan yang dimiliki OLXTOTO adalah koleksi permainan yang luas dan beragam. Dari togel hingga slot online, dari live casino hingga permainan kartu klasik, OLXTOTO memiliki sesuatu untuk setiap pemain. Dibangun dengan teknologi terkini dan dikembangkan oleh para ahli industri, setiap permainan di platform ini dirancang untuk memberikan pengalaman yang tak tertandingi bagi para penjudi. Namun, keunggulan OLXTOTO tidak hanya terletak pada variasi permainan yang mereka tawarkan. Mereka juga menonjol karena komitmen mereka terhadap keamanan dan keadilan. Dengan sistem keamanan tingkat tinggi dan proses audit yang ketat, OLXTOTO memastikan bahwa setiap putaran permainan berjalan dengan adil dan transparan. Para pemain dapat merasa aman dan yakin bahwa pengalaman berjudi mereka di OLXTOTO tidak akan terganggu oleh masalah keamanan atau keadilan. Tak hanya itu, OLXTOTO juga terkenal karena layanan pelanggan yang luar biasa. Tim dukungan mereka selalu siap sedia untuk membantu para pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Dengan respon cepat dan solusi yang efisien, OLXTOTO memastikan bahwa pengalaman berjudi para pemain tetap mulus dan menyenangkan. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi pilihan utama bagi jutaan penjudi online di seluruh dunia. Jika Anda mencari platform yang dapat memberikan kemenangan maksimal dan hasil optimal, tidak perlu mencari lebih jauh dari OLXTOTO. Bergabunglah dengan OLXTOTO hari ini dan mulailah petualangan Anda menuju kemenangan besar dan hasil terbaik!
    • Selamat datang di OLXTOTO, situs slot gacor terpanas yang sedang booming di industri perjudian online. Jika Anda mencari pengalaman bermain yang luar biasa, maka OLXTOTO adalah tempat yang tepat untuk Anda. Dapatkan sensasi tidak biasa dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering. Di sini, Anda akan merasakan keseruan yang luar biasa dalam bermain judi slot. DAFTAR OLXTOTO DISINI LOGIN OLXTOTO DISINI AKUN PRO OLXTOTO DISINI   Jackpot Slot Maxwin Sering Untuk Peluang Besar Di OLXTOTO, kami tidak hanya memberikan hadiah slot biasa, tapi juga memberikan kesempatan kepada pemain untuk memenangkan jackpot slot maxwin yang sering. Dengan demikian, Anda dapat meraih keberuntungan besar dan memenangkan ribuan rupiah sebagai hadiah jackpot slot maxwin kami. Jackpot slot maxwin merupakan peluang besar bagi para pemain judi slot untuk meraih keuntungan yang lebih besar. Dalam permainan kami, Anda tidak harus terpaku pada kemenangan biasa saja. Kami hadir dengan jackpot slot maxwin yang sering, sehingga Anda memiliki peluang yang lebih besar untuk meraih kemenangan besar dengan hadiah yang menggiurkan. Dalam permainan judi slot, pengalaman bermain bukan hanya tentang keseruan dan hiburan semata. Kami memahami bahwa para pemain juga menginginkan kesempatan untuk meraih keberuntungan besar. Oleh karena itu, OLXTOTO hadir dengan jackpot slot maxwin yang sering untuk memberikan peluang besar kepada para pemain kami. Peluang Besar Menang Jackpot Slot Maxwin Peluang menang jackpot slot maxwin di OLXTOTO sangatlah besar. Anda tidak perlu khawatir tentang batasan atau pembatasan dalam meraih jackpot tersebut. Kami ingin memberikan kesempatan kepada semua pemain kami untuk merasakan sensasi menang dalam jumlah yang luar biasa. Jackpot slot maxwin kami dibuka untuk semua pemain judi slot di OLXTOTO. Anda memiliki peluang yang sama dengan pemain lainnya untuk memenangkan hadiah jackpot yang besar. Kami percaya bahwa semua orang memiliki kesempatan untuk meraih keberuntungan besar, dan itulah mengapa kami menyediakan jackpot slot maxwin yang sering untuk memenuhi harapan dan keinginan Anda.   Kesimpulan OLXTOTO adalah situs slot gacor terbaik yang memberikan pengalaman bermain judi slot online yang tak terlupakan. Dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering, OLXTOTO menjadi pilihan terbaik bagi para pemain yang mencari kesenangan dan kemenangan besar dalam perjudian online. Di samping itu, OLXTOTO juga menawarkan layanan pelanggan yang ramah dan responsif, siap membantu setiap pemain dalam mengatasi masalah teknis atau pertanyaan seputar perjudian online. Kami menjaga integritas game dan memberikan lingkungan bermain yang adil serta menjalankan kebijakan perlindungan pelanggan yang cermat. Bergabunglah dengan OLXTOTO sekarang dan nikmati pengalaman bermain slot online yang luar biasa. Jadilah bagian dari komunitas perjudian yang mengagumkan ini dan raih kesempatan untuk meraih kemenangan besar. Dapatkan akses mudah dan praktis ke situs OLXTOTO dan rasakan sensasi bermain judi slot yang tak terlupakan.  
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa Di dunia perjudian online yang begitu kompetitif, mencari platform yang dapat memberikan kemenangan maksimal (Maxwin) dan hasil terbaik (Gacor) adalah prioritas bagi para penjudi yang cerdas. Dalam upaya ini, OLXTOTO telah muncul sebagai pemain kunci yang mengubah lanskap perjudian online dengan menawarkan pengalaman tanpa tandingan.     Sejak diluncurkan, OLXTOTO telah menjadi sorotan industri perjudian online. Dikenal sebagai "Platform Maxwin dan Gacor Terbesar Sepanjang Masa", OLXTOTO telah menarik perhatian pemain dari seluruh dunia dengan reputasinya yang solid dan kinerja yang luar biasa. Salah satu fitur utama yang membedakan OLXTOTO dari pesaingnya adalah komitmen mereka untuk memberikan pengalaman berjudi yang unik dan memuaskan. Dengan koleksi game yang luas dan beragam, termasuk togel, slot online, live casino, dan banyak lagi, OLXTOTO menawarkan sesuatu untuk semua orang. Dibangun dengan teknologi terkini dan didukung oleh tim ahli yang berdedikasi, platform ini memastikan bahwa setiap pengalaman berjudi di OLXTOTO tidak hanya menghibur, tetapi juga menguntungkan. Namun, keunggulan OLXTOTO tidak hanya terletak pada permainan yang mereka tawarkan. Mereka juga terkenal karena keamanan dan keadilan yang mereka berikan kepada para pemain mereka. Dengan sistem keamanan tingkat tinggi dan audit rutin yang dilakukan oleh otoritas regulasi independen, para pemain dapat yakin bahwa setiap putaran permainan di OLXTOTO adalah adil dan transparan. Tidak hanya itu, OLXTOTO juga dikenal karena layanan pelanggan yang luar biasa. Dengan tim dukungan yang ramah dan responsif, para pemain dapat yakin bahwa setiap pertanyaan atau masalah mereka akan ditangani dengan cepat dan efisien. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi platform pilihan bagi para penjudi online yang mencari kemenangan maksimal dan hasil terbaik. Jadi, jika Anda ingin bergabung dengan jutaan pemain yang telah merasakan keajaiban OLXTOTO, jangan ragu untuk mendaftar dan mulai bermain hari ini!  
    • OLXTOTO adalah bandar slot yang terkenal dan terpercaya di Indonesia. Mereka menawarkan berbagai jenis permainan slot yang menarik dan menghibur. Dengan tampilan yang menarik dan grafis yang berkualitas tinggi, pemain akan merasa seperti berada di kasino sungguhan. OLXTOTO juga menyediakan layanan pelanggan yang ramah dan responsif, siap membantu pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Daftar =  https://surkale.me/Olxtotodotcom1
    • DAFTAR & LOGIN BIGO4D   Bigo4D adalah situs slot online yang populer dan menarik perhatian banyak pemain slot di Indonesia. Dengan berbagai game slot yang unik dan menarik, Bigo4D menjadi tempat yang ideal untuk pemula dan pahlawan slot yang berpengalaman. Dalam artikel ini, kami akan membahas tentang Bigo4D sebagai situs slot terbesar dan menarik yang saat ini banyak dijajaki oleh pemain slot online.
  • Topics

×
×
  • Create New...

Important Information

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