package dF.Wirent.functions.impl.render;
import com.google.common.eventbus.Subscribe;
import com.mojang.blaze3d.systems.RenderSystem;
import dF.Wirent.events.WorldEvent;
import dF.Wirent.functions.api.Category;
import dF.Wirent.functions.api.Function;
import dF.Wirent.functions.api.FunctionRegister;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.settings.PointOfView;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.optifine.render.RenderUtils;
@FunctionRegister(name = "BlockOutline", type = Category.Render)
public class BlockOutline extends Function {
@Subscribe
public void onRenderWorldLast(WorldEvent e) {
BlockPos blockPos = findBlockToDisplay();
if (blockPos != null && mc.gameSettings.getPointOfView() == PointOfView.FIRST_PERSON) {
BlockState state = mc.world.getBlockState(blockPos);
if (state.getBlock() != Blocks.AIR && state.getBlock() != Blocks.WATER && state.getBlock() != Blocks.LAVA && state.getBlock() != Blocks.CAVE_AIR && state.getBlock() != Blocks.VOID_AIR) {
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(770, 771, 1, 0);
int color = HUD.getColor(90);
int alpha = 255;
int glowingColor = (color & 0xFFFFFF) | (alpha << 24);
RenderUtils.drawBlockBox(blockPos, glowingColor);
RenderSystem.disableBlend();
}
}
}
private BlockPos findBlockToDisplay() {
RayTraceResult result = mc.objectMouseOver;
if (result instanceof BlockRayTraceResult overlay) {
BlockPos pos = overlay.getPos();
PlayerEntity player = mc.player;
if (player != null) {
double reachDistance = 6.0;
double distanceSq = player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ());
if (distanceSq <= reachDistance * reachDistance) {
return pos;
}
}
}
return null;
}
@Override
protected float[] rotations(PlayerEntity var1) {
return new float[0];
}
}