Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Creating a Fluid


Recommended Posts

Hi Modders,

 

I'm interested in making a fluid in 1.16.x, but I'm running into an issue with textures not loading for the liquid; I'm wondering if it has something to do with the fluid tags as well, but I'm not sure.

 

Here's my code for registering the fluid:

@Mod.EventBusSubscriber
public class FluidMod {

    public static final AmbrosiaFluid.Source AMBROSIA = (AmbrosiaFluid.Source) new AmbrosiaFluid.Source().setRegistryName(BaseMod.MODID, "ambrosia");
    public static final AmbrosiaFluid.Flowing AMBROSIA_FLOWING = (AmbrosiaFluid.Flowing) new AmbrosiaFluid.Flowing().setRegistryName(BaseMod.MODID, "ambrosia_flowing");

    public static final class Tags extends ForgeRegistryEntry<Tags> {
        public static final ITag.INamedTag<Fluid> AMBROSIA = FluidTags.makeWrapperTag("ambrosia");
    }

    @SubscribeEvent
    public static void registerFluids(RegistryEvent.Register<Fluid> event) {
        event.getRegistry().register(AMBROSIA);
        event.getRegistry().register(AMBROSIA_FLOWING);
    }

}

And here is the class for the fluid itself:

public abstract class AmbrosiaFluid extends FlowingFluid {
    @Override
    public Fluid getFlowingFluid() {
        return FluidMod.AMBROSIA_FLOWING;
    }

    @Override
    public Fluid getStillFluid() {
        return FluidMod.AMBROSIA;
    }

    @Override
    protected boolean canSourcesMultiply() {
        return true;
    }

    @Override
    protected void beforeReplacingBlock(IWorld worldIn, BlockPos pos, BlockState state) {
        // If it runs over some grass, what does it do?
    }

    /*
    The shape that this thing forms when it flows out.
     */
    @Override
    protected int getSlopeFindDistance(IWorldReader worldIn) {
        return 4; // Same value as water and lava.
    }

    /*
    How far it goes out; water and lava are both 8.
     */
    @Override
    protected int getLevelDecreasePerBlock(IWorldReader worldIn) {
        return 3;
    }

    /*

     */
    @Override
    public Item getFilledBucket() {
        return ItemMod.BUCKET_AMBROSIA;
    }

    @Override
    protected boolean canDisplace(FluidState p_215665_1_, IBlockReader p_215665_2_, BlockPos p_215665_3_, Fluid p_215665_4_, Direction p_215665_5_) {
        return false;
    }

    @Override
    public int getTickRate(IWorldReader p_205569_1_) {
        return 60;
    }

    @Override
    protected float getExplosionResistance() {
        return 100.0f;
    }

    @Override
    protected BlockState getBlockState(FluidState state) {
        return BlockMod.AMBROSIA_BLOCK.getDefaultState().with(FlowingFluidBlock.LEVEL, Integer.valueOf(getLevelFromState(state)));
    }

    @Override
    public boolean isEquivalentTo(Fluid fluidIn) {
        return fluidIn == FluidMod.AMBROSIA || fluidIn == FluidMod.AMBROSIA_FLOWING;
    }

    @Override
    protected FluidAttributes createAttributes() {
        return FluidAttributes.builder(
                new ResourceLocation(BaseMod.MODID, "textures/block/ambrosia.png"),
                new ResourceLocation(BaseMod.MODID, "textures/block/ambrosia_flowing.png"))
            .translationKey("block.examplemod.ambrosia")
            .build(this);
    }

    public static class Flowing extends AmbrosiaFluid {

        @Override
        protected void fillStateContainer(StateContainer.Builder<Fluid, FluidState> builder) {
            super.fillStateContainer(builder);
            builder.add(LEVEL_1_8);
        }

        @Override
        public boolean isSource(FluidState state) {
            return false;
        }

        @Override
        public int getLevel(FluidState state) {
            return state.get(AmbrosiaFluid.LEVEL_1_8);
        }
    }

    public static class Source extends AmbrosiaFluid {

        @Override
        public boolean isSource(FluidState state) {
            return true;
        }

        @Override
        public int getLevel(FluidState state) {
            return 8;
        }
    }

}

Here is the JSON in the "resources/assets.examplemod/blockstates" folder:

{
  "variants": {
    "": {
      "model": "examplemod:block/ambrosia"
    }
  }
}

And the JSON in the "resources/assets.examplemod/models/block" folder:

{
  "textures": {
    "particle": "examplemod:block/ambrosia"
  }
}

In "resources/assets.examplemod/textures/block", I have the following mcmeta files accompanying the textures:

ambrosia.png.mcmeta:

{
  "animation": {
    "frametime": 2
  }
}

ambrosia_flowing.png.mcmeta:

{
  "animation": {}
}

In "resources/data.examplemod/tags/fluids" I have the following file, "ambrosia.json":

{
  "replace": false,
  "values": [
    "examplemod:ambrosia",
    "examplemod:ambrosia_flowing"
  ]
}

Currently, the fluid appears to be working except for the fact that the texture displays as a purple-black checker pattern.

 

Is it maybe the ambrosia_flowing.png.mcmeta file? All the textures are in the textures folder for blocks.

 

I would really appreciate assistance; I'm actually doing this for a tutoring job (I tutor Minecraft modding on a very basic level), and I would really appreciate insight into what I could do to get the texture to appear.

 

Thank you and thanks in advance!

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.

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.