Skip to content

Commit

Permalink
Fixed losing NBT data from fluids (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdew committed Dec 31, 2016
1 parent f5a1490 commit a629668
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/net/bdew/pressure/blocks/router/TileRouter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import net.bdew.lib.data.base.{TileDataSlotsTicking, UpdateKind}
import net.bdew.lib.multiblock.data.RSMode
import net.bdew.pressure.api.{IPressureConnection, IPressureEject, IPressureInject, PressureAPI}
import net.bdew.pressure.blocks.router.data.{DataSlotSideFilters, DataSlotSideModes, DataSlotSideRSControl, RouterSideMode}
import net.bdew.pressure.misc.FluidUtils
import net.bdew.pressure.pressurenet.Helper
import net.minecraft.util.EnumFacing
import net.minecraftforge.fluids.{Fluid, FluidStack}
Expand Down Expand Up @@ -98,7 +99,7 @@ class TileRouter extends TileDataSlotsTicking with IPressureInject with IPressur
handler.drain(Int.MaxValue, false)
}
if (fluid != null && fluid.getFluid != null && fluid.amount > 0 && isSideValidIO(face, fluid, RouterSideMode.inputs)) {
val ejected = new FluidStack(fluid.getFluid, distributeFluid(fluid, true))
val ejected = FluidUtils.copyStackWithAmount(fluid, distributeFluid(fluid, true))
handler.drain(ejected, true)
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/net/bdew/pressure/misc/FluidUtils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) bdew, 2013 - 2016
* https://github.com/bdew/pressure
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/

package net.bdew.pressure.misc

import net.minecraftforge.fluids.FluidStack

object FluidUtils {
def copyStackWithAmount(fs: FluidStack, amount: Int): FluidStack = {
val tmp = fs.copy()
fs.amount = amount
fs
}
}
5 changes: 3 additions & 2 deletions src/net/bdew/pressure/pressurenet/PressureConnection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package net.bdew.pressure.pressurenet

import net.bdew.pressure.Pressure
import net.bdew.pressure.api.{IPressureConnection, IPressureInject}
import net.bdew.pressure.misc.FluidUtils
import net.minecraft.util.EnumFacing
import net.minecraftforge.fluids.FluidStack

Expand All @@ -36,7 +37,7 @@ case class PressureConnection(origin: IPressureInject, side: EnumFacing, tiles:
// Don't try balancing small amounts
var toPush = fluid.amount
tiles.foreach { target =>
toPush -= target.eject(new FluidStack(fluid.getFluid, toPush), doPush)
toPush -= target.eject(FluidUtils.copyStackWithAmount(fluid, toPush), doPush)
if (toPush <= 0) return fluid.amount
}
toPush - fluid.amount
Expand All @@ -47,7 +48,7 @@ case class PressureConnection(origin: IPressureInject, side: EnumFacing, tiles:
val filled = maxFill map { case (te, amount) =>
val toFill = (amount * mul).floor.toInt
if (toFill > 0)
te.eject(new FluidStack(fluid.getFluid, toFill), doPush)
te.eject(FluidUtils.copyStackWithAmount(fluid, toFill), doPush)
else
0
}
Expand Down

0 comments on commit a629668

Please sign in to comment.