Jump to content

Recommended Posts

Posted

Alright. So I'm doing fluids in my mod for the first time. I couldn't find any tutorials, so I went with this German one (used youtube's caption translate tool):

. As I hadn't done them before, I pretty much just straight up copied the methods from the video. There is one method I changed: ModelBakery#addVariantName -> ModelBakery#registerItemVariants, but apart from that it was all identical. I seem to be getting a multitude of exceptions.

 

Crash report: http://pastebin.com/UCC0L4vn

 

It seems like all of the exceptions are the same, but there is one NullPointerException at the bottom of the file.

 

FluidRenderRegister:

public class FluidRenderRegister {

public static void init() {
	registerFluid(ModBlocks.bloodBlockFluid, "blood");
}

private static void registerFluid(BlockFluidClassic block, String name) {
	Item item = Item.getItemFromBlock(block);
	ModelBakery.registerItemVariants(item);
	final ModelResourceLocation loc = new ModelResourceLocation(Constants.MODID + ":fluids.json", name);
	ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
		@Override
		public ModelResourceLocation getModelLocation(ItemStack stack) {
			return loc;
		}
	});
	ModelLoader.setCustomStateMapper(block, new StateMapperBase() {		
		@Override
		protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
			return loc;
		}
	});
}
}

 

ModBlocks:

public class ModBlocks {

public static BreweryBlock breweryBlock;
public static CatalystLiquidizerBlock catalystLiquidizerBlock;
public static BloodBlockFluid bloodBlockFluid;

public static void init() {
	registerBlockWithItem(breweryBlock = new BreweryBlock(Material.wood),
			 	    Constants.MODID + ":" + Constants.BREWERYBLOCK_UNLOCALIZED);
	registerBlockWithItem(catalystLiquidizerBlock = new CatalystLiquidizerBlock(Material.wood),
					Constants.MODID + ":" + Constants.CATALYSTLIQUIDIZERBLOCK_UNLOCALIZED);
	GameRegistry.register(bloodBlockFluid = new BloodBlockFluid(ModFluids.bloodFluid, Material.water));
}

private static void registerBlockWithItem(Block b, String s) {
	GameRegistry.register(b);
	ItemBlock i = new ItemBlock(b);
	ModelLoader.setCustomModelResourceLocation(i, 0, new ModelResourceLocation(s, "inventory"));
	GameRegistry.register(i.setRegistryName(b.getRegistryName()));
}
}

 

ClientProxy:

public class ClientProxy extends CommonProxy {
@Override
public void preInit(FMLPreInitializationEvent e) {
	super.preInit(e);
}

@Override
public void init(FMLInitializationEvent e) {
	super.init(e);
	BlockRenderRegister.registerBlocks();
	FluidRenderRegister.init();
}

@Override
public void postInit(FMLPostInitializationEvent e) {
	super.postInit(e);
}
}

 

CommonProxy:

public class CommonProxy {

public void preInit(FMLPreInitializationEvent e) {
	ModFluids.init();
	BreweryRecipeHelper.init();
	ModTileEntities.init();
	ModBlocks.init();
}

public void init(FMLInitializationEvent e) {
	NetworkRegistry.INSTANCE.registerGuiHandler(Brewery.brewery, new BreweryGuiHandler());
}

public void postInit(FMLPostInitializationEvent e) {

}

}

 

ModFluids:

public class ModFluids {
public static Fluid bloodFluid;

public static void init() {
	bloodFluid = new GenericFluid("fluid_blood",
			new ResourceLocation(Constants.MODID, "blocks/fluids/fluidblood_still"),
			new ResourceLocation(Constants.MODID, "blocks/fluids/fluidblood_flow"))
			.setViscosity(1500)
			.setLuminosity(5);
	FluidRegistry.registerFluid(bloodFluid);
}
}

 

If you need more files, let me know.

 

It looks like some model files are missing, but the tutorial guy didn't make them so I really don't have a clue as to what I'm supposed to do. Sorry for being Jon Snow (not knowing anything).

 

Thanks :)

Posted

ModelLoader.setCustomMeshDefinition

and

ModelLoader.setCustomStateMapper

must be called in preInit, you should move the

FluidRenderRegister.init

call to the

preInit

method of

ClientProxy

.

 

You should be using

ModelLoader.setCustomModelResourceLocation

and the other

ModelLoader

methods for your regular

Block

s and

Item

s as well as your fluid

Block

s. All of these methods must be called in preInit.

 

Don't include the .json extension in model/blockstate file locations, that's added for you.

 

The

ModelBakery.registerItemVariants

call on line 26 of

FluidRenderRegister

is throwing a

NullPointerException

because you passed it a

null

Item

argument. This is because you never registered an

ItemBlock

for

ModBlocks.bloodBlockFluid

.

 

Calling client-only methods like

ModelLoader.setCustomModelResourceLocation

from common code like

ModBlocks.registerBlockWithItem

will crash the dedicated server. Model registration must be handled through your client proxy.

 

Recipes should generally be added in init rather than preInit.

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.

Posted

ModelLoader.setCustomMeshDefinition

and

ModelLoader.setCustomStateMapper

must be called in preInit, you should move the

FluidRenderRegister.init

call to the

preInit

method of

ClientProxy

.

 

You should be using

ModelLoader.setCustomModelResourceLocation

and the other

ModelLoader

methods for your regular

Block

s and

Item

s as well as your fluid

Block

s. All of these methods must be called in preInit.

 

Don't include the .json extension in model/blockstate file locations, that's added for you.

 

The

ModelBakery.registerItemVariants

call on line 26 of

FluidRenderRegister

is throwing a

NullPointerException

because you passed it a

null

Item

argument. This is because you never registered an

ItemBlock

for

ModBlocks.bloodBlockFluid

.

 

Calling client-only methods like

ModelLoader.setCustomModelResourceLocation

from common code like

ModBlocks.registerBlockWithItem

will crash the dedicated server. Model registration must be handled through your client proxy.

 

Recipes should generally be added in init rather than preInit.

 

So as a rule of thumb all Model* methods should go in my client proxy right?

Posted

So as a rule of thumb all Model* methods should go in my client proxy right?

 

Yes. Anything marked as

@SideOnly(Side.CLIENT)

can only be used from client-only code.

 

This page explains sides in more detail. This thread explains why not to use

@SideOnly

in your own code.

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.

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.