Jump to content

Recommended Posts

Posted (edited)

I was working on my minecraft mod, however I ran into a roadblock when attempting to create a new liquid called magic water. Here is my code:

 

 

 

//Registry handler

import com.Epic_ModZz.Magically_Magic.init.EntityInit;
import com.Epic_ModZz.Magically_Magic.init.FluidInit;
import com.Epic_ModZz.Magically_Magic.init.ModBlocks;
import com.Epic_ModZz.Magically_Magic.init.ModItems;
import com.Epic_ModZz.Magically_Magic.util.IHasModel;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@EventBusSubscriber
public class RegistryHandler {
	@SubscribeEvent
	public static void onItemRegister(RegistryEvent.Register<Item> event)
	{
		event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0]));
	}
	
	@SubscribeEvent
	public static void onBlockRegister(RegistryEvent.Register<Block> event)
	{
		event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0]));
	} 
	
	
	@SubscribeEvent
	public static void onModelRegister(ModelRegistryEvent event)
	{
		for(Item item : ModItems.ITEMS)
		{
			if(item instanceof IHasModel)
			{
				((IHasModel)item).registerModels();
			}
		}
		
		
		for(Block block : ModBlocks.BLOCKS)
		{
			if(block instanceof IHasModel)
			{
				((IHasModel)block).registerModels();
			} 
		}		
		
	}
	
	public static void preInitRegistries() {
		FluidInit.registerFluids();
		EntityInit.registerEntities();
		RenderHandlers .registerCustomMeshesAndStates();
	}
}

 

//FluidInit

import com.Epic_ModZz.Magically_Magic.fluids.FluidLiquid;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;

public class FluidInit {
	public static final Fluid MAGIC_WATER = new FluidLiquid("magical_solution", new ResourceLocation("magi:blocks/magical_solution_still"), new ResourceLocation("magi:blocks/magical_solution_flowing"));
	
	
	
	public static void registerFluids() {
		registerFluid(MAGIC_WATER);
	}
	public static void registerFluid(Fluid fluid) {
		FluidRegistry.registerFluid(fluid);
		FluidRegistry.addBucketForFluid(fluid);
	}
}

 

//FluidLiquid

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;

public class FluidLiquid extends Fluid{

	public FluidLiquid(String name, ResourceLocation still, ResourceLocation flow) {
		super(name, still, flow);
		this.setUnlocalizedName(name);
	}
}

 

The person who fixes my error may suggest something to be added into the mod. This must be within reason however.

 

Edit: The error that this code causes is a crash when loading. In the console it said "Cannot create a fluidstack from an unregistered fluid"

 

Edited by Epic_ModZz
Posted (edited)
21 minutes ago, Animefan8888 said:

Do you ever call this method? And if you do where?

 

I do in my main file

 

//Main

import com.Epic_ModZz.Magically_Magic.init.EntityInit;
import com.Epic_ModZz.Magically_Magic.proxy.CommonProxy;
import com.Epic_ModZz.Magically_Magic.util.Reference;
import com.Epic_ModZz.Magically_Magic.util.handlers.RegistryHandler;
import com.Epic_ModZz.Magically_Magic.util.handlers.RenderHandlers;

import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)
public class Main {
	
	@Instance
	public static Main instance;
	
	@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.COMMON_PROXY_CLASS)
	public static CommonProxy proxy;
	
	
	static { FluidRegistry.enableUniversalBucket(); }
	
	@EventHandler
	public static void PreInit(FMLPreInitializationEvent event)
	{

		RenderHandlers.registerEntityRenders();	
	}
	
	@EventHandler
	public static void Init(FMLInitializationEvent event)
	{
		RegistryHandler.preInitRegistries();
	}
	
	@EventHandler
	public static void PostInit(FMLPostInitializationEvent event)
	{
		
	}	

}

 

Edited by Epic_ModZz
Posted
10 minutes ago, Epic_ModZz said:

RegistryHandler.preInitRegistries();

Does this get called try putting a println here. Also it's called preInitRegistries why is it in init? Secondly anything to do with rendering can't be done in the main mod class/common code use your ClientProxy.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
36 minutes ago, Animefan8888 said:

Does this get called try putting a println here. Also it's called preInitRegistries why is it in init? Secondly anything to do with rendering can't be done in the main mod class/common code use your ClientProxy.

 

 

I put a print statement here

 

	@EventHandler
	public static void PreInit(FMLPreInitializationEvent event)
	{
		System.out.print("ERRROOROROROROROROR");
		RenderHandlers.registerEntityRenders();	
	}

 

It printed that statement right before the error occured

 

11:31:18] [Client thread/INFO] [FML]: Found 0 ItemStackHolder annotations
[11:31:20] [Client thread/INFO] [FML]: Configured a dormant chunk cache size of 0
[11:31:20] [Forge Version Check/INFO] [forge.VersionCheck]: [forge] Starting version check at http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json
ERRROOROROROROROROR[11:31:21] [Forge Version Check/INFO] [forge.VersionCheck]: [forge] Found status: OUTDATED Target: 14.23.5.2847
[11:31:28] [Client thread/WARN] [FML]: ****************************************
[11:31:28] [Client thread/WARN] [FML]: * Failed attempt to create a FluidStack for an unregistered Fluid magical_solution (type com.Epic_ModZz.Magically_Magic.fluids.FluidLiquid)

 

 

As for your second question, I was just following a mod tutorial. If I need to change the structure of my mod's files please let me know how to do that.

 

 

This is what is in my client proxy btw:

 

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;

public class ClientProxy extends CommonProxy {
	public void registerItemRenderer(Item item, int meta, String id)
	{
		ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), id));
	}
}

 

Edited by Epic_ModZz
Posted
23 minutes ago, Epic_ModZz said:

System.out.print("ERRROOROROROROROROR"); RenderHandlers.registerEntityRenders();

That's not where I asked you to put it...

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
6 minutes ago, Animefan8888 said:

That's not where I asked you to put it...

I put it here and it didn't show up in console:/

	public static void preInitRegistries() {
		System.out.print("Testing Error");
		FluidInit.registerFluids();
		EntityInit.registerEntities();
		RenderHandlers .registerCustomMeshesAndStates();
	}

 

Edited by Epic_ModZz
Posted
4 hours ago, Epic_ModZz said:

I put it here and it didn't show up in console

It's not printing because the game crashes during preInit. You're calling that method during init. That's probably also why your Fluid is unregistered when the FluidStack is being made.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted (edited)
15 minutes ago, SerpentDagger said:

It's not printing because the game crashes during preInit. You're calling that method during init. That's probably also why your Fluid is unregistered when the FluidStack is being made.

 

Where should I put it then?

 

Edit: thx I just fixed it :D is there anything u want in the mod (within reason)

Edited by Epic_ModZz
  • 1 year later...
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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