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

[1.16.x][Question]fluid generators


raziel23x
 Share

Recommended Posts

I was trying to find some information and documentation about making a lava or water generator like i would do with ItemStack but with Fluids but unable to find much i been following tutorials in making basic items/tools/armor and excited i was able to figure but i started the process but got stuck after getting this far

RegistryHandler.java

package raziel23x.projectskyblock.utils;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import raziel23x.projectskyblock.ProjectSkyblock;
import raziel23x.projectskyblock.blocks.*;

public class RegistryHandler {

public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ProjectSkyblock.MOD_ID);
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ProjectSkyblock.MOD_ID);
    private static final DeferredRegister<TileEntityType<?>> TILES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, ProjectSkyblock.MOD_ID);
  
  public static final RegistryObject<Block> LAVA_GENERATOR_BLOCK  = BLOCKS.register("lava_generator_block", LavaGeneratorBlock::new);
   public static final RegistryObject<Item> LAVA_GENERATOR_BLOCK_ITEM = ITEMS.register("lava_generator_block", () -> new BlockItemBaseLavaGenerator(LAVA_GENERATOR_BLOCK.get()));
  public static final RegistryObject<TileEntityType<LavaGeneratorTile>> LAVAGENERATOR_TILE = TILES.register("lava_generator_block", () -> TileEntityType.Builder.create(LavaGeneratorTile::new, LAVA_GENERATOR_BLOCK.get()).build(null));
  public static void init() {
        ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
        BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        TILES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }

}

  

 

LavaGeneratorBlock.java

package raziel23x.projectskyblock.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockReader;

import javax.annotation.Nullable;

public class LavaGeneratorBlock extends Block {
    public LavaGeneratorBlock(){
        super(Properties.create(Material.ROCK)
                .sound(SoundType.STONE)
                .hardnessAndResistance(2.0f)
        );

    }

    @Override
    public boolean hasTileEntity(BlockState state) {
        return true;
    }

    @Nullable
    @Override
    public TileEntity createTileEntity(BlockState state, IBlockReader world) {
        return new LavaGeneratorTile();
    }
}

 

LavaGeneratorTile.java

package raziel23x.projectskyblock.blocks;

import net.minecraft.fluid.Fluids;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.templates.FluidTank;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static raziel23x.projectskyblock.utils.RegistryHandler.LAVAGENERATOR_TILE;

public class LavaGeneratorTile extends TileEntity implements ITickableTileEntity {
    private int tick;
    public LavaGeneratorTile() {
        super(LAVAGENERATOR_TILE.get());
    }

    @Override
    public void tick() {
        tick++;
        if (tick == 10) {
            tick = 0;
            FluidStack stack = new FluidStack(Fluids.LAVA, Integer.MAX_VALUE);
         // CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY

        }
    }

    public LazyOptional<FluidTank> fluidHandler = LazyOptional.of(this::createFluidHandler);

    public FluidTank getFluidHandler() {
        return fluidHandler.orElseThrow(RuntimeException::new);
    }

    @Nonnull
    @Override
    public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
        if (!this.removed) {
            if (cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
                return this.fluidHandler.cast();
            }
        }
        return super.getCapability(cap, side);
    }

    private FluidTank createFluidHandler() {
        return new FluidTank(FluidAttributes.BUCKET_VOLUME * 8) {
            @Override
            protected void onContentsChanged() {
                markDirty();
            }
        };
    }
}

 

BlockItemBaseLavaGenerator.java

package raziel23x.projectskyblock.blocks;

import net.minecraft.block.Block;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import raziel23x.projectskyblock.ProjectSkyblock;

import java.util.List;


public class BlockItemBaseLavaGenerator extends BlockItem {
    public BlockItemBaseLavaGenerator(Block block) {
        super(block, new Properties().group(ProjectSkyblock.TAB).maxStackSize(1));
    }
    @OnlyIn(Dist.CLIENT)
    @Override
    public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
        tooltip.add((new TranslationTextComponent("tip."+ProjectSkyblock.MOD_ID+".LavaGeneratorline1").mergeStyle(TextFormatting.GREEN)));
        tooltip.add((new TranslationTextComponent("tip."+ProjectSkyblock.MOD_ID+".LavaGeneratorline2").mergeStyle(TextFormatting.YELLOW)));
        super.addInformation(stack, worldIn, tooltip, flagIn);
    }


}

 

out on my own about a simple cobblegen and though i would try my hand at doing one for water and lava just to see if i can pull it off but cant seem to find much information

 

i am just lost and maybe someone could point me in the right direction

Edited by raziel23x

Please Kill me i am married with 2 kids HELP!!!!!!!!

Link to comment
Share on other sites

If I remember correctliiy there are some nbt tags about how much an container is filled with fluids.

I wouldn't recommend doing the graphical interface yourself.

I am sure there are some libaries which could handle the graphics for you.

 

If you want to find out which blockdata to add to your block:

Download any mod which adds fluid containers

place one of them in your world 

then read out the blockdata of the block

/blockdata x y z 

x y and z can be retrieved by typing out / blockdata  and then pressing [Tab] for each coordinate whilst looking directly at the block of your destination

 

I hope I could help

I am going to research an fluid interface 

https://gist.github.com/WesCook/c9e282e49580588dd397350283e7e4e1

here is an topic discussion explaining how to do it

here you can find a list of libaries:

https://www.curseforge.com/minecraft/mc-mods/library-api

 

I hope I could help...

Dennis out!

Link to comment
Share on other sites

Vanilla buckets know nothing about a modded block whose tile entity offers a fluid capability.  You need to code the bucket-filling logic in your block's onBlockActivated() method.  Tip: don't just check for a bucket, check for any item which offers the CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, since that would also allow other mod fluids containers (tanks etc.) to be filled from your block.

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.