Search in sources :

Example 1 with DrawMultipartHighlightEvent

use of mcmultipart.api.event.DrawMultipartHighlightEvent in project LogisticsPipes by RS485.

the class MCMPProxy method onDrawHighlight.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onDrawHighlight(DrawBlockHighlightEvent event) {
    if (event instanceof DrawMultipartHighlightEvent) {
        return;
    }
    RayTraceResult hit = event.getTarget();
    if (hit.typeOfHit != RayTraceResult.Type.BLOCK) {
        return;
    }
    BlockPos pos = hit.getBlockPos();
    EntityPlayer player = event.getPlayer();
    if (player == null) {
        return;
    }
    World world = player.world;
    if (world == null) {
        return;
    }
    if (world.getBlockState(pos).getBlock() == LPBlocks.pipe) {
        Optional<TileMultipartContainer> tile = BlockMultipartContainer.getTile(world, pos);
        if (!tile.isPresent()) {
            return;
        }
        int slotID = hit.subHit;
        if (slotID < 0) {
            return;
        }
        PartInfo info = tile.get().getParts().get(MCMultiPart.slotRegistry.getValue(slotID));
        if (info == null || !(hit.hitInfo instanceof RayTraceResult)) {
            return;
        }
        hit = (RayTraceResult) hit.hitInfo;
        float partialTicks = event.getPartialTicks();
        if (!MinecraftForge.EVENT_BUS.post(new DrawMultipartHighlightEvent(event.getContext(), player, hit, slotID, partialTicks, info))) {
            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);
            IBlockState state = info.getState();
            if (state.getMaterial() != Material.AIR && world.getWorldBorder().contains(pos)) {
                double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
                double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
                double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
                RenderGlobal.drawSelectionBoundingBox(info.getPart().getSelectedBoundingBox(info).grow(0.002).offset(-x, -y, -z), 0.0F, 0.0F, 0.0F, 0.4F);
            }
            GlStateManager.depthMask(true);
            GlStateManager.enableTexture2D();
            GlStateManager.disableBlend();
        }
        event.setCanceled(true);
    }
}
Also used : LPTileMultipartContainer(network.rs485.logisticspipes.proxy.mcmp.subproxy.LPTileMultipartContainer) TileMultipartContainer(mcmultipart.block.TileMultipartContainer) IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PartInfo(mcmultipart.multipart.PartInfo) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) DrawMultipartHighlightEvent(mcmultipart.api.event.DrawMultipartHighlightEvent) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

DrawMultipartHighlightEvent (mcmultipart.api.event.DrawMultipartHighlightEvent)1 TileMultipartContainer (mcmultipart.block.TileMultipartContainer)1 PartInfo (mcmultipart.multipart.PartInfo)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 LPTileMultipartContainer (network.rs485.logisticspipes.proxy.mcmp.subproxy.LPTileMultipartContainer)1