Jump to content

1.12.2 fluid registry issues


Epic_ModZz

Recommended Posts

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

11 hours ago, Epic_ModZz said:

public static void preInitRegistries() {

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

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.

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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