Search in sources :

Example 1 with ItemBlockBaseAddon

use of omtteam.openmodularturrets.items.blocks.ItemBlockBaseAddon in project OpenModularTurrets by OpenModularTurretsTeam.

the class EventHandler method drawBlockOutline.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void drawBlockOutline(DrawBlockHighlightEvent event) {
    if (event.getTarget() != null && event.getTarget().getBlockPos() != null && event.getTarget().sideHit != null && event.getPlayer().getHeldItemMainhand() != null && event.getPlayer().getHeldItemMainhand().getItem() instanceof ItemBlockBaseAddon) {
        BlockPos blockpos = event.getTarget().getBlockPos().offset(event.getTarget().sideHit);
        if (getTurretBase(event.getPlayer().getEntityWorld(), blockpos) != null) {
            ItemBlockBaseAddon addon = (ItemBlockBaseAddon) event.getPlayer().getHeldItemMainhand().getItem();
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
            GlStateManager.glLineWidth(2.0F);
            GlStateManager.disableTexture2D();
            GlStateManager.depthMask(false);
            AxisAlignedBB alignedBB;
            EnumFacing facing = getTurretBaseFacing(event.getPlayer().getEntityWorld(), blockpos);
            if (addon.getBlock().getDefaultState().getProperties().containsKey(FACING)) {
                alignedBB = addon.getRenderOutline(addon.getBlock().getDefaultState().withProperty(FACING, facing), event.getPlayer().getEntityWorld(), blockpos);
            } else {
                alignedBB = addon.getRenderOutline(addon.getBlock().getDefaultState(), event.getPlayer().getEntityWorld(), blockpos);
            }
            EntityPlayer player = event.getPlayer();
            double partialTicks = event.getPartialTicks();
            double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
            double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
            double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
            float[] color = new float[3];
            if (event.getPlayer().getEntityWorld().isAirBlock(blockpos)) {
                color[0] = 0F;
                color[1] = 1F;
                color[2] = 1F;
            } else {
                color[0] = 1F;
                color[1] = 0F;
                color[2] = 0F;
            }
            alignedBB = alignedBB.offset(-d0, -d1, -d2);
            Tessellator tessellator = Tessellator.getInstance();
            VertexBuffer vertexbuffer = tessellator.getBuffer();
            vertexbuffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
            drawHighlightBox(vertexbuffer, alignedBB.minX, alignedBB.minY, alignedBB.minZ, alignedBB.maxX, alignedBB.maxY, alignedBB.maxZ, color[0], color[1], color[2], 0.5F);
            tessellator.draw();
            GlStateManager.depthMask(true);
            GlStateManager.enableTexture2D();
            GlStateManager.disableBlend();
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemBlockBaseAddon(omtteam.openmodularturrets.items.blocks.ItemBlockBaseAddon) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

Tessellator (net.minecraft.client.renderer.Tessellator)1 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EnumFacing (net.minecraft.util.EnumFacing)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 ItemBlockBaseAddon (omtteam.openmodularturrets.items.blocks.ItemBlockBaseAddon)1