Skip to content

Commit

Permalink
pipes now damage you :wide:
Browse files Browse the repository at this point in the history
  • Loading branch information
YoungOnionMC committed May 30, 2024
1 parent d8b5cdf commit 3100dc0
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,35 @@
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.FluidPipeProperties;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.api.fluids.FluidConstants;
import com.gregtechceu.gtceu.api.fluids.FluidState;
import com.gregtechceu.gtceu.api.fluids.GTFluid;
import com.gregtechceu.gtceu.api.fluids.attribute.FluidAttribute;
import com.gregtechceu.gtceu.api.pipenet.IPipeNode;
import com.gregtechceu.gtceu.client.model.PipeModel;
import com.gregtechceu.gtceu.common.blockentity.FluidPipeBlockEntity;
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.minecraft.world.level.material.Fluid;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
Expand Down Expand Up @@ -105,4 +116,42 @@ 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;
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 3100dc0

Please sign in to comment.