From dd3897cb071621aa3ce2bf9d53195c7292a7b3f5 Mon Sep 17 00:00:00 2001 From: YoungOnion <39562198+YoungOnionMC@users.noreply.github.com> Date: Thu, 30 May 2024 00:02:17 -0600 Subject: [PATCH] Pipes now damage you :wide: (#1344) * pipes now damage you :wide: * null check :sunglasses: --- .../gtceu/common/block/FluidPipeBlock.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/java/com/gregtechceu/gtceu/common/block/FluidPipeBlock.java b/src/main/java/com/gregtechceu/gtceu/common/block/FluidPipeBlock.java index 2d5840cc4b..1bb19807bf 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/block/FluidPipeBlock.java +++ b/src/main/java/com/gregtechceu/gtceu/common/block/FluidPipeBlock.java @@ -11,17 +11,26 @@ import com.gregtechceu.gtceu.common.data.GTBlockEntities; import com.gregtechceu.gtceu.common.pipelike.fluidpipe.FluidPipeType; import com.gregtechceu.gtceu.common.pipelike.fluidpipe.LevelFluidPipeNet; +import com.gregtechceu.gtceu.utils.EntityDamageUtil; import com.gregtechceu.gtceu.utils.GTUtil; +import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; + import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.ForgeCapabilities; import org.jetbrains.annotations.Nullable; @@ -107,4 +116,45 @@ public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List 1) { + // apply temperature damage for the hottest and coldest pipe (multi fluid pipes) + int maxTemperature = Integer.MIN_VALUE; + int minTemperature = Integer.MAX_VALUE; + for (var tank : pipe.getFluidTanks()) { + FluidStack stack = tank.getFluid(); + net.minecraftforge.fluids.FluidStack forgeStack = FluidHelperImpl.toFluidStack(stack); + if (tank.getFluid() != null && tank.getFluid().getAmount() > 0) { + maxTemperature = Math.max(maxTemperature, + stack.getFluid().getFluidType().getTemperature(forgeStack)); + minTemperature = Math.min(minTemperature, + stack.getFluid().getFluidType().getTemperature(forgeStack)); + } + } + if (maxTemperature != Integer.MIN_VALUE) { + EntityDamageUtil.applyTemperatureDamage(livingEntity, maxTemperature, 1.0F, 20); + } + if (minTemperature != Integer.MAX_VALUE) { + EntityDamageUtil.applyTemperatureDamage(livingEntity, minTemperature, 1.0F, 20); + } + } else { + var tank = pipe.getFluidTanks()[0]; + if (tank.getFluid() != null && tank.getFluid().getAmount() > 0) { + // Apply temperature damage for the pipe (single fluid pipes) + FluidStack stack = tank.getFluid(); + net.minecraftforge.fluids.FluidStack forgeStack = FluidHelperImpl.toFluidStack(stack); + EntityDamageUtil.applyTemperatureDamage(livingEntity, + stack.getFluid().getFluidType().getTemperature(forgeStack), 1.0F, 20); + } + } + } + } + } }