Skip to content

Commit

Permalink
fix gtnh-found null fluid tank info crash
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Aug 28, 2022
1 parent 33eb8cb commit e84596e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* Fixed: Missing null check for Blood Magic integration.
* Fixed: [#3336] Missing null check for GregTech data stick NBTs.
* Fixed: [#3249] NullPointerException when remote terminal is missing.
* Fixed: Potential edge case crash with the Tank Controller Upgrade.
* Fixed: [#3401] 'rawSetForeground', 'rawSetBackground' not working correctly.
* Fixed: [#3265] Relay 'setStrength' unlimited upper bound. (JamesOrdner)
* (1.7.10) Fixed: [#3540] Server-side crash with Motion Sensor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ trait WorldTankAnalytics extends WorldAware with SideRestricted {
def getTankCount(context: Context, args: Arguments): Array[AnyRef] = {
val facing = checkSideForAction(args, 0)
FluidUtils.fluidHandlerAt(position.offset(facing)) match {
case Some(handler) => result(handler.getTankInfo(facing.getOpposite).length)
case Some(handler) => handler.getTankInfo(facing.getOpposite) match {
case info: Array[FluidTankInfo] => result(info.length)
case _ => result(Unit, "no tank")
}
case _ => result(Unit, "no tank")
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/li/cil/oc/util/ExtendedArguments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ object ExtendedArguments {

def checkTankInfo(handler: IFluidHandler, side: ForgeDirection, n: Int) = {
val tank = args.checkInteger(n) - 1
if (tank < 0 || tank >= handler.getTankInfo(side).length) {
val tankInfo = handler.getTankInfo(side)
if (tankInfo == null || tank < 0 || tank >= tankInfo.length) {
throw new IllegalArgumentException("invalid tank index")
}
handler.getTankInfo(side)(tank)
tankInfo(tank)
}

def optTankInfo(handler: IFluidHandler, side: ForgeDirection, n: Int, default: FluidTankInfo) = {
Expand Down

0 comments on commit e84596e

Please sign in to comment.