Search in sources :

Example 1 with ICustomHighlight

use of buildcraft.core.lib.client.render.ICustomHighlight in project BuildCraft by BuildCraft.

the class BlockHighlightHandler method handleBlockHighlight.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void handleBlockHighlight(DrawBlockHighlightEvent e) {
    if (e.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
        int x = MathHelper.floor_double(e.target.hitVec.xCoord);
        int y = MathHelper.floor_double(e.target.hitVec.yCoord);
        int z = MathHelper.floor_double(e.target.hitVec.zCoord);
        BlockPos pos = new BlockPos(x, y, z);
        IBlockState state = e.player.worldObj.getBlockState(pos);
        Block block = state.getBlock();
        if (block instanceof ICustomHighlight) {
            AxisAlignedBB[] aabbs = ((ICustomHighlight) block).getBoxes(e.player.worldObj, pos, state);
            Vec3d nPos = e.player.getPositionEyes(e.partialTicks).subtract(0, e.player.getEyeHeight(), 0);
            // Highlight "breathing"
            long millis = System.currentTimeMillis();
            float expansion = (millis % 5000) / 2500F - 1;
            expansion *= Math.PI * 2;
            expansion = (MathHelper.sin(expansion) + 1) / 2;
            expansion *= ((ICustomHighlight) block).getBreathingCoefficent();
            GL11.glEnable(GL11.GL_BLEND);
            OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
            GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
            GL11.glLineWidth(2F);
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glDepthMask(false);
            double exp = ((ICustomHighlight) block).getExpansion();
            exp += expansion / 32D;
            nPos = nPos.subtract(x, y, z);
            for (AxisAlignedBB aabb : aabbs) {
                AxisAlignedBB changed = aabb.expand(exp, exp, exp).offset(-nPos.xCoord, -nPos.yCoord, -nPos.zCoord);
                RenderGlobal.drawSelectionBoundingBox(changed);
            }
            GL11.glDepthMask(true);
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glDisable(GL11.GL_BLEND);
            e.setCanceled(true);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ICustomHighlight(buildcraft.core.lib.client.render.ICustomHighlight) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ICustomHighlight (buildcraft.core.lib.client.render.ICustomHighlight)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1