Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I recently started creating a test example for a six way block and tried to waterlog it. I then tried to extending it to all fluids but not only would it render, it would also throw an error if the fluid block being read wasn't the source. I'm not sure what to do to allow any fluid at any level to render properly and work correctly when the block contains a fluid. I know that it has something to do with Block#getFluidState however I'm not sure why.

 

Block class:

Spoiler

public class BlockWire extends BlockSixWay implements IBucketPickupHandler, ILiquidContainer {

    public static final BooleanProperty HAS_FLUID = BooleanProperty.create("has_fluid");
    
    public BlockWire(Properties builder) {
        super(.0625f, builder);
        this.setDefaultState(this.stateContainer.getBaseState().with(NORTH, false).with(SOUTH, false).with(EAST, false).with(WEST, false).with(UP, false).with(DOWN, false).with(HAS_FLUID, false));
    }

    @Override
    public boolean isFullCube(IBlockState state) {
        return false;
    }
    
    @Override
    public BlockRenderLayer getRenderLayer() {
        return BlockRenderLayer.CUTOUT;
    }
    
    @Override
    protected void fillStateContainer(Builder<Block, IBlockState> builder) {
        builder.add(NORTH, EAST, SOUTH, WEST, UP, DOWN, HAS_FLUID);
    }
    
    @Override
    public IBlockState getStateForPlacement(BlockItemUseContext context) {
        Block down = context.getWorld().getBlockState(context.getPos().down()).getBlock();
        Block up = context.getWorld().getBlockState(context.getPos().up()).getBlock();
        Block east = context.getWorld().getBlockState(context.getPos().east()).getBlock();
        Block west = context.getWorld().getBlockState(context.getPos().west()).getBlock();
        Block north = context.getWorld().getBlockState(context.getPos().north()).getBlock();
        Block south = context.getWorld().getBlockState(context.getPos().south()).getBlock();
        return this.getDefaultState().with(DOWN, canConnect(down)).with(UP, canConnect(up)).with(EAST, canConnect(east)).with(WEST, canConnect(west)).with(NORTH, canConnect(north)).with(SOUTH, canConnect(south)).with(HAS_FLUID, !context.getWorld().getFluidState(context.getPos()).isEmpty());
    }
    
    @Override
    public IBlockState updatePostPlacement(IBlockState stateIn, EnumFacing facing, IBlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
        return stateIn.with(FACING_TO_PROPERTY_MAP.get(facing), canConnect(facingState.getBlock()));
    }
    
    private boolean canConnect(Block facingBlock) {
        return facingBlock instanceof BlockWire;
    }
    
    @Override
    public boolean canContainFluid(IBlockReader worldIn, BlockPos pos, IBlockState state, Fluid fluidIn) {
        return !state.get(HAS_FLUID);
    }

    @Override
    public boolean receiveFluid(IWorld worldIn, BlockPos pos, IBlockState state, IFluidState fluidStateIn) {
        if(!state.get(HAS_FLUID)) {
            if(!worldIn.isRemote()) {
                worldIn.setBlockState(pos, state.with(HAS_FLUID, true), 3);
                worldIn.getPendingFluidTicks().scheduleTick(pos, fluidStateIn.getFluid(), fluidStateIn.getFluid().getTickRate(worldIn));
            }
            return true;
        }
        return false;
    }

    @Override
    public Fluid pickupFluid(IWorld worldIn, BlockPos pos, IBlockState state) {
        if(state.get(HAS_FLUID)) {
            worldIn.setBlockState(pos, state.with(HAS_FLUID, false), 3);
            return worldIn.getFluidState(pos).getFluid();
        }
        return Fluids.EMPTY;
    }
    
    @Override
    public IFluidState getFluidState(IBlockState state) {
        return state.get(HAS_FLUID) ? state.getFluidState() : Fluids.EMPTY.getDefaultState();
    }
}

 

Error:

Spoiler

[12Aug2019 16:04:35.614] [Server thread/FATAL] [net.minecraft.server.MinecraftServer/]: Error executing task
java.util.concurrent.ExecutionException: java.lang.StackOverflowError
    at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_201]
    at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_201]
    at net.minecraft.util.Util.runTask(Util.java:127) [?:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:770) [?:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:724) [?:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:122) [?:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:611) [?:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
Caused by: java.lang.StackOverflowError
    at com.google.common.collect.RegularImmutableMap.get(RegularImmutableMap.java:123) ~[guava-21.0.jar:?]
    at com.google.common.collect.RegularImmutableMap.get(RegularImmutableMap.java:115) ~[guava-21.0.jar:?]
    at net.minecraft.state.AbstractStateHolder.get(AbstractStateHolder.java:94) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]
    at io.github.championash5357.minecraftextensions.block.BlockWire.getFluidState(BlockWire.java:97) ~[?:?]
    at net.minecraft.block.state.IBlockState.getFluidState(IBlockState.java:355) ~[?:?]

 

7 hours ago, ChampionAsh5357 said:

state.getFluidState()

Your code is looping. Its infinite recursion. Your getFluidState method calls BlockState#getFluidState which calls your method again.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
18 hours ago, Animefan8888 said:

Your code is looping. Its infinite recursion. Your getFluidState method calls BlockState#getFluidState which calls your method again.

You know I feel like such an idiot sometimes. But then comes the problem of having multiple fluids inside the block. Do I need to create a state for each fluid? If so, then would it require to have a state for the flowing version and the source version? What would come about for modded fluids then as well? I don't really see a way to have a state for each fluid in the game dynamically.

Edited by ChampionAsh5357

  • Author

After changing my code to match Minecraft's style, there seems to be no support for liquid containers other than water. If that's the case, how would you get other liquids to render inside the block? It seems like this system was only made for one instance and no other case.

You'll probably have to wait until Forge's fluid system rewrite is completed, I'm pretty sure the Vanilla system only really supports water.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.