From 450a7042f919a04d790bd4b295b43ed8287c6ca4 Mon Sep 17 00:00:00 2001 From: Yang Xizhi <60341015+GlodBlock@users.noreply.github.com> Date: Sat, 11 Dec 2021 20:50:46 +0800 Subject: fix NPE (#794) * make the debuff time depend on contents * fix npe in fluid --- .../java/gregtech/common/blocks/GT_Item_Machines.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/main/java/gregtech/common/blocks/GT_Item_Machines.java') diff --git a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java index b95a1728d1..fb8a9cbe89 100644 --- a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java @@ -244,13 +244,16 @@ public class GT_Item_Machines extends ItemBlock implements IFluidContainerItem { if (tNBT == null) return; if ((tNBT.hasKey("mItemCount") && tNBT.getInteger("mItemCount") > 0) || (tNBT.hasKey("mFluid") && FluidStack.loadFluidStackFromNBT(tNBT.getCompoundTag("mFluid")).amount > 64000)) { - double tFluidAmount = FluidStack.loadFluidStackFromNBT(tNBT.getCompoundTag("mFluid")).amount; - double tMiddlePoint = 4096000; - double tSmoothingCoefficient = 2000000; - int tMaxLastingTime = 12000; - double tmp = (tFluidAmount - tMiddlePoint) / tSmoothingCoefficient; - int tLasing = (int) (Math.exp(tmp) / (Math.exp(tmp) + Math.exp(-tmp)) * tMaxLastingTime); - if (tFluidAmount == 0) tLasing = 1200; + FluidStack tFluid = FluidStack.loadFluidStackFromNBT(tNBT.getCompoundTag("mFluid")); + int tLasing = 1200; + if (tFluid != null) { + double tFluidAmount = tFluid.amount; + double tMiddlePoint = 4096000; + double tSmoothingCoefficient = 2000000; + int tMaxLastingTime = 12000; + double tmp = (tFluidAmount - tMiddlePoint) / tSmoothingCoefficient; + tLasing = (int) (Math.exp(tmp) / (Math.exp(tmp) + Math.exp(-tmp)) * tMaxLastingTime); + } tPlayer.addPotionEffect(new PotionEffect(Potion.hunger.id, tLasing, 4)); tPlayer.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, tLasing, 4)); tPlayer.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, tLasing, 4)); -- cgit