Skip to content

Commit

Permalink
Pipes now damage you :wide: (#1344)
Browse files Browse the repository at this point in the history
* pipes now damage you :wide:

* null check 😎
  • Loading branch information
YoungOnionMC authored May 30, 2024
1 parent 093f964 commit dd3897c
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,4 +116,45 @@ public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List<C
if (properties.isCryoProof()) tooltip.add(Component.translatable("gtceu.fluid_pipe.cryo_proof"));
if (properties.isPlasmaProof()) tooltip.add(Component.translatable("gtceu.fluid_pipe.plasma_proof"));
}

@Override
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
if (level.isClientSide) return;
if (level.getBlockEntity(pos) == null) return;
FluidPipeBlockEntity pipe = (FluidPipeBlockEntity) level.getBlockEntity(pos);
if (pipe.getOffsetTimer() % 10 == 0) {
if (entity instanceof LivingEntity livingEntity) {
if (pipe.getFluidTanks().length > 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);
}
}
}
}
}
}

0 comments on commit dd3897c

Please sign in to comment.