BuildCraft|Factory

BuildCraft|Factory

7M Downloads

[7.99.13-pre10] Automatically ejecting fluid into an adjacent BC pipe

LordMonoxide opened this issue ยท 5 comments

commented

Buildcraft version: tested on 7.99.12-pre9, 7.99.13-pre10
Forge version: 14.23.1.2561

I'm working on a mod which has a machine that automatically ejects a fluid out of the top. When I have an IFluidHandler (e.g. one of my machines that accepts a fluid) sitting on top, the fluid transfers as expected. However, BC pipes refuse to accept the fluid.

Unfortunately I don't have much more information at the moment... BuildCraft's bytecode at runtime doesn't seem to match the decompiled source. Any information on why this is would be appreciated as well.

The code I'm using is very simple:

FluidUtil.tryFluidTransfer(this.autoOutput, this.tankSteam, 10, true);

In this case, this.autoOutput is an instance of PipeFlowFluids$Section. The code executes as expected, draining a FluidStack of amount 10 out of this.tankSteam. When the code reaches FluidUtil#tryFluidTransfer_Internal, it executes the following:

int fillableAmount = fluidDestination.fill(drainable, false);

fillableAmount ends up being 0.

I believe it may be due to the following BC code (but again, I can't verify, because of the bytecode/source issue):

if (!getCurrentDirection().canInput() || !pipe.isConnected(part.face) || resource == null) {
    return 0;
}
commented

what are you decompiling the jar for? all code is available here in this repo

the pump and other modded machines do output fine to fluid pipes so i suspect there is something in your code, can you link to the entire code from your end (or join the discord to chat about it?)

commented

@LordMonoxide Does the fluid pipe visibly connect to your block? If it doesn't then that will be the primary problem - you'll have to add an IFluidHandler of some sort to getCapability() in order to get them to connect.

commented

@AEnterprise I'm decompiling/deobfuscating since BC is currently a dependency of my mod. I'm pulling it in from Maven. Interestingly enough, I just checked my project settings and BC did have a source attachment... when I removed the attachment and let IntelliJ decompile it itself, the bytecode and source do match up.

With the ability to step through the source, I was able to track down the issue.

  public void neighborChanged(final IBlockState state, final World world, final BlockPos pos, final Block block, final BlockPos neighbor) {
    super.neighborChanged(state, world, pos, block, neighbor);
    
    final TileEntity te = world.getTileEntity(pos);
    
    final BlockPos rel = neighbor.subtract(pos);
    final EnumFacing side = EnumFacing.getFacingFromVector(rel.getX(), rel.getY(), rel.getZ());
    
    if(side == EnumFacing.UP) {
      final IFluidHandler handler = FluidUtil.getFluidHandler(world, neighbor, side);
      
      if(te instanceof TileBronzeBoiler) {
        ((TileBronzeBoiler)te).updateOutput(handler);
      }
    }
  }

Note the call to FluidUtil#getFluidHandler. side is EnumFacing.UP, but the side of the pipe I wanted was EnumFacing.DOWN. My bad :(

Is there a better way I should be pulling in BC?

commented

In theory using maven should be correct... perhaps it needed to be refreshed? Seeing as you tested with prereleases (and the maven repo doesn't have pre-releases) did something get modified when you pulled?

commented

I should have noted that I didn't test it with the pre-releases in the IDE. I'm using the latest maven release in my dev environment, and tested the newer builds in a live environment to see if it may have been a BC bug that was already fixed. (Sorry, was struggling with this until laaaaaaaaaate last night, and made this post as soon as I woke up.)

Anyway, thanks for the help!