Jump to content

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


Cmonster

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
    • Hi guys! I am having some issues with the server crashing over and over and I was hoping to get some guidance.  Thanks in advance! Crash 1: java.lang.Error: ServerHangWatchdog detected that a single server tick took 60.00 seconds (should be max 0.05)     at net.minecraft.server.dedicated.ServerWatchdog.run(ServerWatchdog.java:43) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at java.lang.Thread.run(Thread.java:840) ~[?:?] { Crash 2: java.lang.IllegalStateException: Capability missing for eeb7f026-34b4-42f5-9164-e7736461df83     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.lambda$get$0(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at net.minecraftforge.common.util.LazyOptional.orElseThrow(LazyOptional.java:261) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:mixin,re:classloading}     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.get(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:143) ~[?:?] {}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:129) ~[?:?] {}     at com.mojang.brigadier.tree.CommandNode.canUse(CommandNode.java:65) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parseNodes(CommandDispatcher.java:359) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:349) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:317) ~[brigadier-1.1.8.jar%2376!/:?] {}     at net.minecraft.commands.Commands.m_230957_(Commands.java:237) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at net.mcreator.boh.procedures.TeleportbenProcedure.lambda$execute$2(TeleportbenProcedure.java:65) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.BohMod.lambda$tick$2(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {re:mixin}     at net.mcreator.boh.BohMod.tick(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.__BohMod_tick_ServerTickEvent.invoke(.dynamic) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading,pl:eventbus:B}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at java.lang.Thread.run(Thread.java:840) ~[?:?] {}
  • Topics

×
×
  • Create New...

Important Information

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