Jump to content

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


Recommended Posts

Posted

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)
    {
        
    }

}
 

 

Posted (edited)

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

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

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

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

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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