diff options
author | Yang Xizhi <60341015+GlodBlock@users.noreply.github.com> | 2021-12-11 20:50:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-11 13:50:46 +0100 |
commit | 450a7042f919a04d790bd4b295b43ed8287c6ca4 (patch) | |
tree | fe58f61e64d5f01636875faaa81bb6225b665dc0 /src/main/java/gregtech/common/blocks/GT_Item_Machines.java | |
parent | 243e8e0f3c88ecc7b242f92e640b6082d7891f42 (diff) | |
download | GT5-Unofficial-450a7042f919a04d790bd4b295b43ed8287c6ca4.tar.gz GT5-Unofficial-450a7042f919a04d790bd4b295b43ed8287c6ca4.tar.bz2 GT5-Unofficial-450a7042f919a04d790bd4b295b43ed8287c6ca4.zip |
fix NPE (#794)
* make the debuff time depend on contents
* fix npe in fluid
Diffstat (limited to 'src/main/java/gregtech/common/blocks/GT_Item_Machines.java')
-rw-r--r-- | src/main/java/gregtech/common/blocks/GT_Item_Machines.java | 17 |
1 files changed, 10 insertions, 7 deletions
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)); |