Jump to content

Forge Fluid Creation


Mksn

Recommended Posts

Hi guys, I am pretty new on Minecraft Modding. I am trying to create custom fluid using forge recently, but it just couldn't work. I suspect there's something wrong with the registry. Emmm, so, please help me Orz. Down here are my codes.

 

public class FluidBase extends Fluid implements IHasModel
{
    static
    {
        FluidRegistry.enableUniversalBucket();
    }
    public FluidBase(String name, Material material)
    {
        this(name, material, new ResourceLocation("fluid/"+ name + "_still"), new ResourceLocation("fluid/" + name + "_flowing"));
    }
    
    public FluidBase(String name, Material material, ResourceLocation still, ResourceLocation flowing)
    {
        super(name, still, flowing);
        block = new BlockFluidClassic(this, material);
        block.setUnlocalizedName(name);
        block.setRegistryName("fluid " + name);
        Item item = new ItemBlock(block);
        item.setRegistryName(name);
        ModFluid.FLUID.add(this);
        ModBlocks.BLOCKS.add(block);
        ModItems.ITEMS.add(item);
    }
    
    @Override
    public void registerModel()
    {
        Main.proxy.registerFluidModel(Item.getItemFromBlock(this.getBlock()), this.getBlock(), this.getName());
    }
}

 

I created a class FluidBase, which extends fluid from net.minecraft. As most tutorials suggested, I also created a corresponding block using BlockFluidClassModFluid.FLUID,  ModBlocks.BLOCKS, and ModItems.ITEMS are just three arraylists for registering the objects. (IHasModel only contains the method registerModel(), which is overridden here.)

 

@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]));
    }
     

    public static void onFluidRegister()
    {
        for(Fluid object : ModFluid.FLUID)
        {
            FluidRegistry.registerFluid(object);
            FluidRegistry.addBucketForFluid(object);   
        }
    }
    
    @SubscribeEvent
    public static void onModelRegister(ModelRegistryEvent event)
    {
        for(Item item : ModItems.ITEMS)
        {
            if(item instanceof IHasModel)
            {
                ((IHasModel)item).registerModel();
            }
            
        }
        
        for(Block block : ModBlocks.BLOCKS)
        {
            if(block instanceof IHasModel)
            {
                ((IHasModel)block).registerModel();
            }
            
        }
    }
}

 

After I declared an instance of FluidBase, I created several subscribe event methods. I did not put the annotation @SubscribeEvent before onFluidRegister(), since i saw there is an event bus method built into the FluidRegistry.registerFluid() method.

 

 

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

    @Override
    public void registerFluidModel(Item item, Block block, String name)
    {
        ModelBakery.registerItemVariants(item);
        ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition()
        {
            @Override
            public ModelResourceLocation getModelLocation(ItemStack stack)
            {
                return new ModelResourceLocation(Reference.MOD_ID + ":" + name , name);
            }
        });
        ModelLoader.setCustomStateMapper(block, new StateMapperBase()
        {
            @Override
            protected ModelResourceLocation getModelResourceLocation(IBlockState state)
            {
                return new ModelResourceLocation(Reference.MOD_ID + ":" + name , name);
            }
        });
    }
}

 

Here is my client proxy, model registry basically, about which I have no idea Lol. I copied most of the code from MCreator here.

 

@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;
    
    @EventHandler
    public static void PreInit(FMLPreInitializationEvent event)
    {
        RegistryHandler.onFluidRegister();
    }
    
    @EventHandler
    public static void Init(FMLInitializationEvent event){}
    
    @EventHandler
    public static void PostInit(FMLPostInitializationEvent event){]
}

 

Lastly, here is my Main method. As a website instructed, I put the fluidregistry inside preinit. (I didn't mess with the item and block registries since forge docs state they are between preinit and init.)

 

Well.. Somehow, as a result of these terrible codes the game wouldn't load and would crash every time. Here's the console:

error.txt

There's like other texture problems as well, but please just ignore these for now...

I know there's probably some really dumb problems here in the code. I have just started codding, so please offer some help Orz. I would be very grateful~~~

Link to comment
Share on other sites

This is how you post code:

 

Capture.PNG

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

  • 3 weeks later...

Emmm, I kinda got busy in school recently, so I havent gotten much progress.

checked the code again and compared it with many tutorials, not many differences.

But still encountering issues with the registry.

I guess its some of the nuance that caused errors, tried many changes but didnt work.

can someone check it for me plez?

Link to comment
Share on other sites

5 minutes ago, Mksn said:

Emmm, I kinda got busy in school recently, so I havent gotten much progress.

checked the code again and compared it with many tutorials, not many differences.

But still encountering issues with the registry.

I guess its some of the nuance that caused errors, tried many changes but didnt work.

can someone check it for me plez?

Post your new code please and do it properly please, either using the code button on the forums or using github. As well as the log from the latest run where the problem still persists.

 

On 8/1/2018 at 7:26 AM, Mksn said:

I copied most of the code from MCreator here.

Dear god. Please stay away from MCreator. It is a terrible program and it could have been done so much better to actually help people learn haw to code as well as its code structure for the mod ??

On 8/1/2018 at 7:26 AM, Mksn said:

I have just started codding

You should learn java before trying to create a mod, because it is like trying to learn how to ride a motorcycle before you learn how to ride a tricycle.

On 8/1/2018 at 7:26 AM, Mksn said:

There's like other texture problems as well, but please just ignore these for now...

If these aren't cause by the fluid please comment out the code causing them. This will make the error easier to spot.

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

7 hours ago, Animefan8888 said:

You should learn java before trying to create a mod, because it is like trying to learn how to ride a motorcycle before you learn how to ride a tricycle.

If you don’t know java but know another Object Oriented Programming language (like JavaScript or PHP or C++) it’s going to be like going from crawling to walking.

 

If you don’t know an Object Oriented Programming language but do know something like C, it will be like going from crawling to riding a bike.

 

If you know nothing about Programming, it will be like learning to fly a helicopter when you can’t even crawl yet

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

1 hour ago, Cadiboo said:

If you know nothing about Programming, it will be like learning to fly a helicopter when you can’t even crawl yet

Eh, I think even if someone could walk, flying a helicopter would be a pretty daunting task. :P

 

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

14 minutes ago, Mksn said:

But can someone give me some ideas on what went wrong in the code? or some constructive advice?

 

19 hours ago, Animefan8888 said:

Post your new code please and do it properly please, either using the code button on the forums or using github. As well as the log from the latest run where the problem still persists.

 

19 hours ago, Animefan8888 said:

Dear god. Please stay away from MCreator. It is a terrible program and it could have been done so much better to actually help people learn haw to code as well as its code structure for the mod ??

 

19 hours ago, Animefan8888 said:

If these aren't cause by the fluid please comment out the code causing them. This will make the error easier to spot.

 

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

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.