Jump to content

Forge fluids, help with creative tab, name, and crafting recipe. 1.11.2


Cmonster
 Share

Recommended Posts

Hello, I have created a fluid called mercury, and have enabled universal bucket and have done FluidRegistry.addBucketForFluid(ModFluids.FluidMercury.instance);

However, I don't know how to name the filled bucket using the lang file or putting it in the creative tab. Also, I would like to know the way to add a crafting recipe for the filled mercury bucket.

Any help would be greatly appreciated, as well as example code for these items.

Fluid class:

Spoiler

package init;

import com.Cmonster.OreMod.Reference;
import com.Cmonster.OreMod.creativetabs.TabElements;

import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModFluids {
    
    private static ModelResourceLocation mercury_location = new ModelResourceLocation(Reference.MOD_ID + ":" + BlockMercury.name, "fluid");
    
    public static void register() {
        FluidRegistry.registerFluid(FluidMercury.instance);
        GameRegistry.register(BlockMercury.instance, mercury_location);
        Item mercury = Item.getItemFromBlock(BlockMercury.instance);
        ModelLoader.setCustomMeshDefinition(mercury, new ItemMeshDefinition() {
            
            @Override
            public ModelResourceLocation getModelLocation(ItemStack stack) {
                return mercury_location;
            }
        });
        ModelLoader.setCustomStateMapper(BlockMercury.instance, new StateMapperBase() {
            
            @Override
            protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
                return mercury_location;
            }
        });
        FluidRegistry.addBucketForFluid(FluidMercury.instance);
    }
    
    public static final class FluidMercury extends Fluid {
        
        public static final String name = "mercury";
        public static final FluidMercury instance = new FluidMercury();
        
        public FluidMercury() {
            super(name, new ResourceLocation(Reference.MOD_ID + ":" + "blocks/" + name  + "_still"), new ResourceLocation(Reference.MOD_ID + ":" + "blocks/" + name  + "_flow"));
            this.setViscosity(100);
        }
    }
    
    public static final class BlockMercury extends BlockFluidClassic {
        
        public static final BlockMercury instance = new BlockMercury();
        public static final String name = "mercury";
        
        public BlockMercury() {
            super(FluidMercury.instance, Material.WATER);
            setUnlocalizedName("blockmercury");

        }
        
        @Override
        public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
            if(entityIn instanceof EntityLivingBase) {
                ((EntityLivingBase)entityIn).addPotionEffect(new PotionEffect(Potion.getPotionById(19), 100, 2, false, false));
            }
        }
        
        @Override
        public EnumBlockRenderType getRenderType(IBlockState state) {
            return EnumBlockRenderType.MODEL;
        }
    }
}

Mod class:

Spoiler

package com.Cmonster.OreMod;

import com.Cmonster.OreMod.proxy.CommonProxy;
import com.Cmonster.OreMod.worldgen.OreGen;

import handlers.RecipeHandler;
import init.ModArmor;
import init.ModBlocks;
import init.ModFluids;
import init.ModItems;
import init.ModTools;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
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;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION, acceptedMinecraftVersions = Reference.ACCEPTED_VERSIONS)
public class OreMod {

    @Instance
    public static OreMod instance;
    
    @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
    public static CommonProxy proxy;
    
    static {
        FluidRegistry.enableUniversalBucket();
    }
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        ModFluids.register();
        FluidRegistry.addBucketForFluid(ModFluids.FluidMercury.instance);
        ModBlocks.init();
        ModBlocks.register();
        ModItems.init();
        ModItems.register();
        ModTools.init();
        ModTools.register();
        ModArmor.init();
        ModArmor.register();
        
    }
    
    @EventHandler
    public void Init(FMLInitializationEvent event)
    {
        proxy.init();
        
        GameRegistry.registerWorldGenerator(new OreGen(), 0);
        RecipeHandler.registerCraftingRecipes();
        RecipeHandler.registerFurnaceRecipes();
    }
    
    @EventHandler
    public void PostInit(FMLPostInitializationEvent event)
    {
        
    }

}
 

 

Link to comment
Share on other sites

To add a bucket to your fluid you would call FluidRegistry::addBucketForFluid. As you are doing. Is something not working correctly?

It will be added to a creative tab that all buckets are at(I believe it is the Miscellaneous tab) if you call that method.

Do not name the bucket, name the fuild(Fluid::setUnlocalizedName) and localize that, the bucket will be localized from there. 

Forge uses capabilities to store fluids in the bucket and so will you. Create an itemstack of a bucket, access it's capabilities and add your fluid into it using the capability. After that just return that stack as a result of your recipe.

 

15 minutes ago, Cmonster said:

 public static void register()

 

15 minutes ago, Cmonster said:

 ModelLoader.setCustomMeshDefinition

You can't call client side code from a common class or you will crash the server.

 

15 minutes ago, Cmonster said:

 public void preInit(FMLPreInitializationEvent event)
    {
        ModFluids.register();
        FluidRegistry.addBucketForFluid(ModFluids.FluidMercury.instance);

 

15 minutes ago, Cmonster said:

public static void register() {
        FluidRegistry.registerFluid(FluidMercury.instance);
        GameRegistry.register(BlockMercury.instance, mercury_location);
        ...
        FluidRegistry.addBucketForFluid(FluidMercury.instance);

You are adding a bucket twice. Granted it should not matter as bucketFluids is a set and set can't usually contain equal elements within but that is still redundant.

 

15 minutes ago, Cmonster said:

 ((EntityLivingBase)entityIn).addPotionEffect(new PotionEffect(Potion.getPotionById(19), 100, 2, false, false));

Potion.getPotionById(19)? What is 19? Where is this magical number coming from? Why are you even using Potion::getPotionById? You have the MobEffects class at net.minecraft.init that contains all potion instances.

Edited by V0idWa1k3r
Link to comment
Share on other sites

22 minutes ago, V0idWa1k3r said:

Potion.getPotionById(19)? What is 19? Where is this magical number coming from? Why are you even using Potion::getPotionById? You have the MobEffects class at net.minecraft.init that contains all potion instances.

I will fix the rest of the code, but the reason i'm using 19 is because it's the effect id for poison. Unless this way is any different from using the potion instances from the MobEffects class, I don't think I need to change it for my purposes.

 

Anyway, thanks for the response and tips.

Link to comment
Share on other sites

Just now, Cmonster said:

Unless this way is any different from using the potion instances from the MobEffects class, I don't think I need to change it for my purposes.

Getting a registry object by ID requires a map lookup every time you do so. Getting an effect from a field requires... getting it from a field. The performance is way better if you use the later.

It also generates a more readable code. Imagine yourself looking at this code 6 months later. Will you remember what this 19 is there for? What if IDs change? You will have to spend time figuring it out and that is not productive.

Link to comment
Share on other sites

On 6/11/2017 at 2:19 PM, V0idWa1k3r said:

Forge uses capabilities to store fluids in the bucket and so will you. Create an itemstack of a bucket, access it's capabilities and add your fluid into it using the capability. After that just return that stack as a result of your recipe.

Honestly, I'm not sure where to start here. I have fixed most other things, but i've been stuck here for a while. I'm new to modding, so if you could get me started with this, that would be great.

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I figured out what was wrong ... you can spot it pretty quick most likely: { "type": "minecraft:smelting", "ingredient": { "item": "minecraft:gold_nugget_ore" }, "result": "minecraft:gold_nugget", "experience": 0.25, "cookingtime": 150 }   ... so, after changing `minecraft` to `foundations` for all the custom items and all the recipes work. Well that's what copy/paste will get you. One last question about recipes, though. What does the following json key/value do in the game? "group": "copper_ingot"  
    • # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # #      102.54.94.97     rhino.acme.com          # source server #       38.25.63.10     x.acme.com              # x client host # localhost name resolution is handled within DNS itself. #    127.0.0.1       localhost #    ::1             localhost ###0.0.0.0 apps.corel.com ###0.0.0.0 mc.corel.com 0.0.0.0 origin-mc.corel.com ###0.0.0.0 iws.corel.com
    • Is there a way to create a custom map marker for a custom structure/biome (same as a vanilla mansion)?
    • I’ve scrounged the Internet for solutions and found absolutely nothing that has worked for me I have posted my code in a GitHub Repository. I bet the culprit is somewhere in the Container or TileEntity classes (Furnace packages are in blocks/coke_furnace or blocks/foundry) PS I know I’m on 1.12.2 and that it’s not supported I don’t want to update my game or my code. Lol It’s my favorite version and the most widely modded. I don’t plan to release the mod, I’m just customizing my game to my will. I’ll send it to friends but that’s it.
    • 1.19.2 With forge 43.2.4   https://mclo.gs/zCAx1MG      
  • Topics

×
×
  • Create New...

Important Information

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